I have some javascript inside an iframe that sends the height of the iframe body to the parent page using the three frame technique at Resizing an iframe based on content
The height of the iframes body always seems to come out at 900, the viewport height of the iframe. This is consistent across browsers.
The iframe:
<iframe id="printiq" src="http://myurl.com" height="900px" width="980px">Your browser does not support iframes.</iframe>
The script inside the iframe:
$(window).load(function() {
var height = document.body.scrollHeight + 60;
alert('Height: ' + height); //Always returns 900, the height of the iframe
var whirlwind_url = 'http://whirlwind.ben.dev/iframe_helper';
var iframe_html = '<iframe id="height_helper" src="'+whirlwind_url+'?height='+height+'"></iframe>';
$('body').append(iframe_html);
});
The weird thing is when I inspect the DOM with firebug none of the height variables (scrollHeight, offsetHeight etc) are set to 900.
The problem was a div on the iframed page was expanding to the height of the viewport. I fixed it by changing the css.
Here is the code I ended up with.
Parent window.
The script for the iframed external site.
});
The iframe helper, which gets embedded into the iframe. A grandchild of the browser window if you like.