Last active
September 7, 2016 10:00
-
-
Save LukeFF/95e4fd8e2696325f4f413a7f52570e36 to your computer and use it in GitHub Desktop.
automatic Iframe resizing without Cross-Origin issues
This file contains hidden or 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
<body onLoad="resizeParent();"> | |
<script type="text/javascript"> | |
function resizeParent() { | |
var height = document.getElementsByTagName("html")[0].scrollHeight; | |
window.parent.postMessage(["setIframeHeight", height], "*"); | |
} | |
</script> | |
</body> |
This file contains hidden or 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
<iframe id="superFrame" src="iframe.html" style="width: 100%; border: none;" scrolling="no" height="500"></iframe> | |
<script type="text/javascript"> | |
window.addEventListener('message', function(e) { | |
var iframe = document.getElementById('superFrame'); | |
var eventName = e.data[0]; | |
var height = e.data[1]; | |
switch(eventName) { | |
case 'setIframeHeight': | |
iframe.height = height; | |
break; | |
} | |
}, false); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment