Last active
May 8, 2018 17:24
-
-
Save fazlurr/507a4de80fb9d2a6f63ffc6c56bb37cf to your computer and use it in GitHub Desktop.
This file contains 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
function resizeIFrameToFitContent( iFrame ) { | |
iFrame.width = iFrame.contentWindow.document.body.scrollWidth; | |
iFrame.height = iFrame.contentWindow.document.body.scrollHeight; | |
} | |
window.addEventListener('DOMContentLoaded', function(e) { | |
var iFrame = document.getElementById( 'iFrame1' ); | |
resizeIFrameToFitContent( iFrame ); | |
// or, to resize all iframes: | |
var iframes = document.querySelectorAll("iframe"); | |
for( var i = 0; i < iframes.length; i++) { | |
resizeIFrameToFitContent( iframes[i] ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment