Skip to content

Instantly share code, notes, and snippets.

@secretpray
Created January 30, 2021 06:27
Show Gist options
  • Save secretpray/48c85126803e665ab320a59874e15109 to your computer and use it in GitHub Desktop.
Save secretpray/48c85126803e665ab320a59874e15109 to your computer and use it in GitHub Desktop.
<script type="application/javascript">
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] );
}
} );
</script>
<iframe src="usagelogs/default.aspx" id="iFrame1"></iframe>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment