This question already has an answer here:
For example:
<iframe name="Stack" src="http://stackoverflow.com/" width="740"
frameborder="0" scrolling="no" id="iframe"> ...
</iframe>
I want it to be able to adjust its height according to the contents inside it, without using scroll.
I wanted to make an
iframe
behave like a normal page (I needed to make a fullscreen banner inside aniframe
element), so here is my script:The functions are self-explanatory and have comments to further explain their purpose.
Here is a compact version:
This option will work 100%
The hjpotter92 answer works well enough in certain cases, but I found the iframe content often got bottom-clipped in Firefox & IE, while fine in Chrome.
The following works well for me and fixes the clipping problem. The code was found at http://www.dyn-web.com/tutorials/iframes/height/. I have made a slight modification to take the onload attribute out of the HTML. Place the following code after the
<iframe>
HTML and before the closing</body>
tag:Your iframe HTML:
Note if you prefer to include the Javascript in the
<head>
of the document then you can revert to using an inlineonload
attribute in theiframe
HTML, as in the dyn-web web page.add this to your iframe: onload="autoResize('youriframeid')"