I know this get's asked a lot, but how do I set the dynamic height of a cross domain iframe, when I don't have access to the actual page the IFRAME is showing?
Cross Domain IFRAME resize
2.7k views Asked by 1321941 At
4
There are 4 answers
0

I was having this issue too but I finally got a solution:
Put this code inside the <head>
:
<script type="text/javascript">
function resizeCrossDomainIframe(id, other_domain) {
var iframe = document.getElementById(id);
window.addEventListener('message', function(event) {
if (event.origin !== other_domain) return; // only accept messages from the specified domain
if (isNaN(event.data)) return; // only accept something which can be parsed as a number
var height = parseInt(event.data) + 0; // add some extra height to avoid scrollbar
iframe.height = height + "px";
}, false);
};
</script>
Then, use this code for the iframe:
<iframe src='http://www.example.com/my-iframe/' frameborder="0" id="my_iframe" onload="resizeCrossDomainIframe('my_iframe', 'http://www.example.com');">
You can't. There is no way to know what the height of the document in the frame is from outside the frame because all information about the document is protected from third party sites.