Skip to content

Instantly share code, notes, and snippets.

@mahype
Last active January 15, 2020 17:48
Show Gist options
  • Save mahype/fa0d976a6420083d9b77bf8c0277d06d to your computer and use it in GitHub Desktop.
Save mahype/fa0d976a6420083d9b77bf8c0277d06d to your computer and use it in GitHub Desktop.
Sending iframe height via JS to parent document.
let get_document_height = function () {
var body = document.body,
html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
return height;
}
let send_document_height = function () {
var height = get_document_height();
parent.postMessage( JSON.stringify( {'frame_height': height} ), '*' );
}
if ( window.addEventListener ) {
window.addEventListener( 'load', send_document_height, false );
} else if ( window.attachEvent ) { // ie8
window.attachEvent('onload', send_document_height );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment