Last active
August 29, 2015 14:26
-
-
Save julienw/f4bc2da56d1ac43a49da to your computer and use it in GitHub Desktop.
set iframe height
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 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); | |
} |
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
<!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> |
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
<!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