Skip to content

Instantly share code, notes, and snippets.

@fazlurr
Last active May 8, 2018 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fazlurr/507a4de80fb9d2a6f63ffc6c56bb37cf to your computer and use it in GitHub Desktop.
Save fazlurr/507a4de80fb9d2a6f63ffc6c56bb37cf to your computer and use it in GitHub Desktop.
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