Skip to content

Instantly share code, notes, and snippets.

@GoToLoop GoToLoop/adjustFrame.js
Last active Jun 6, 2019

Embed
What would you like to do?
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
)
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
);
}
// @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
);
}
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
You can’t perform that action at this time.