Skip to content

Instantly share code, notes, and snippets.

@GoToLoop
Last active November 15, 2022 02:27
Show Gist options
  • Save GoToLoop/9eeb3ea918e9e149ba3c6c717cfb16e1 to your computer and use it in GitHub Desktop.
Save GoToLoop/9eeb3ea918e9e149ba3c6c717cfb16e1 to your computer and use it in GitHub Desktop.
Expands Current iFrame Element to Fit Body's Size
'use strict';
function adjustFrameSize() {
if (frameElement) {
frameElement.height = frameElement.frameBorder = 0;
frameElement.height = getDocHeight() + 'px';
frameElement.width = getDocWidth() + 'px';
}
}
function getDocWidth() {
return Math.max(
document.body.scrollWidth, document.documentElement.scrollWidth,
document.body.offsetWidth, document.documentElement.offsetWidth,
document.body.clientWidth, document.documentElement.clientWidth
);
}
function getDocHeight() {
return Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
}
'use strict'
adjustFrameSize = ->
if frameElement
frameElement.height = frameElement.frameBorder = 0
frameElement.height = getDocHeight() + 'px'
frameElement.width = getDocWidth() + 'px'
getDocWidth = ->
Math.max(
document.body.scrollWidth, document.documentElement.scrollWidth
document.body.offsetWidth, document.documentElement.offsetWidth
document.body.clientWidth, document.documentElement.clientWidth
)
getDocHeight = ->
Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight
document.body.offsetHeight, document.documentElement.offsetHeight
document.body.clientHeight, document.documentElement.clientHeight
)
// @ts-check
"use strict";
function adjustFrameSize() {
/** @type {HTMLIFrameElement} */
const frame = frameElement;
if (frame) {
frame.height = frame.frameBorder = '0';
frame.height = getDocHeight() + 'px';
frame.width = getDocWidth() + 'px';
}
}
function getDocWidth() {
return Math.max(
document.body.scrollWidth, document.documentElement.scrollWidth,
document.body.offsetWidth, document.documentElement.offsetWidth,
document.body.clientWidth, document.documentElement.clientWidth
);
}
function getDocHeight() {
return Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
}
export default adjustFrameSize = ->
if frameElement
frameElement.height = frameElement.frameBorder = 0
frameElement.height = getDocHeight() + 'px'
frameElement.width = getDocWidth() + 'px'
export getDocWidth = ->
Math.max(
document.body.scrollWidth, document.documentElement.scrollWidth
document.body.offsetWidth, document.documentElement.offsetWidth
document.body.clientWidth, document.documentElement.clientWidth
)
export getDocHeight = ->
Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight
document.body.offsetHeight, document.documentElement.offsetHeight
document.body.clientHeight, document.documentElement.clientHeight
)
// @ts-check
export default function adjustFrameSize() {
/** @type {HTMLIFrameElement} */
const frame = frameElement;
if (frame) {
frame.height = frame.frameBorder = '0';
frame.height = getDocHeight() + 'px';
frame.width = getDocWidth() + 'px';
}
}
export function getDocWidth() {
return Math.max(
document.body.scrollWidth, document.documentElement.scrollWidth,
document.body.offsetWidth, document.documentElement.offsetWidth,
document.body.clientWidth, document.documentElement.clientWidth
);
}
export function getDocHeight() {
return Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
}
export default function adjustFrameSize() {
const frame = frameElement as HTMLIFrameElement;
if (frame) {
frame.height = frame.frameBorder = '0';
frame.height = getDocHeight() + 'px';
frame.width = getDocWidth() + 'px';
}
}
export function getDocWidth() {
return Math.max(
document.body.scrollWidth, document.documentElement.scrollWidth,
document.body.offsetWidth, document.documentElement.offsetWidth,
document.body.clientWidth, document.documentElement.clientWidth
);
}
export function getDocHeight() {
return Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
}
function adjustFrameSize() {
const frame = frameElement as HTMLIFrameElement;
if (frame) {
frame.height = frame.frameBorder = '0';
frame.height = getDocHeight() + 'px';
frame.width = getDocWidth() + 'px';
}
}
function getDocWidth() {
return Math.max(
document.body.scrollWidth, document.documentElement.scrollWidth,
document.body.offsetWidth, document.documentElement.offsetWidth,
document.body.clientWidth, document.documentElement.clientWidth
);
}
function getDocHeight() {
return Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment