I am loading an aspx web page in an iframe. The content in the Iframe can be of more height than the iframe's height. The iframe should not have scroll bars.
I have a wrapper div
tag inside the iframe which basically is all the content. I wrote some jQuery to make the resize happen :
$("#TB_window", window.parent.document).height($("body").height() + 50);
where
TB_window
is the div in which the Iframe
is contained.
body
- the body tag of the aspx in the iframe.
This script is attached to the iframe content. I am getting the TB_window
element from the parent page. While this works fine on Chrome, but the TB_window collapses in Firefox. I am really confused/lost on why that happens.
you could also add a repeating requestAnimationFrame to your resizeIframe (e.g. from @BlueFish's answer) which would always be called before the browser paints the layout and you could update the height of the iframe when its content have changed their heights. e.g. input forms, lazy loaded content etc.
your callback should be fast enough to have no big impact on your overall performance
and / or
See Stack Overflow question How to get the height of a body element.
Try this to find the height of the body in jQuery:
It doesn't have a value if Firebug. Perhaps that's the problem.
A slightly improved answer to Aristos...
Then declare in your iframe as follows:
There are two minor improvements:
iframe.height = ""
if you're going to reassign it in the very next statement. Doing so actually incurs an overhead as you're dealing with a DOM element.