Skip to content

Instantly share code, notes, and snippets.

@brianherbert
Last active December 14, 2015 07:59
Show Gist options
  • Save brianherbert/5054343 to your computer and use it in GitHub Desktop.
Save brianherbert/5054343 to your computer and use it in GitHub Desktop.
Lock an iframe within an iframe to
<style>
body { background-color:green;text-align:center;}
iframe { padding:0; margin:0; overflow: hidden; border: 0px;}
</style>
<script>
function iframeLoaded() {
var iframe = document.getElementById('testframe');
if(iframe) {
var body = iframe.contentDocument.body;
body.style.padding = 0;
body.style.margin = 0;
// here you can meke the height, I delete it first, then I make it again
iframe.height = "";
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
iframe.width = "";
iframe.width = iframe.contentWindow.document.body.scrollWidth + "px";
}
}
</script>
<body>
<iframe id="testframe" src='originalEmbed.html' onload="iframeLoaded()" />
</body>
<iframe width="560" height="315" src="http://www.youtube.com/embed/CrQf6cogMuI?list=FLZd7fRw0Pi4pYmg3aV10d7Q" frameborder="0" allowfullscreen></iframe>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment