Skip to content

Instantly share code, notes, and snippets.

@julienw
Last active August 29, 2015 14:26
Show Gist options
  • Save julienw/f4bc2da56d1ac43a49da to your computer and use it in GitHub Desktop.
Save julienw/f4bc2da56d1ac43a49da to your computer and use it in GitHub Desktop.
set iframe height
function setIframeHeight() {
window.removeEventListener('load', setIframeHeight); // good citizen
if (window.frameElement) {
window.frameElement.height = document.documentElement.scrollHeight;
}
}
if (document.readyState === 'complete') {
setIframeHeight();
} else {
window.addEventListener('load', setIframeHeight);
}
<!doctype html>
<html>
<head>
<style>
.takes-height {
height: 800px;
width: 500px;
background-color: #dfd;
border: 5px solid #faa;
}
</style>
<script src='iframe-height.js' async></script>
</head>
<body>
<div class='takes-height'></div>
</body>
</html>
<!doctype html>
<html>
<body>
<iframe src='iframe.html' frameborder='0' scrolling='no' width='1000' height='600'></iframe>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment