Last active
January 15, 2020 17:48
-
-
Save mahype/fa0d976a6420083d9b77bf8c0277d06d to your computer and use it in GitHub Desktop.
Sending iframe height via JS to parent document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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