View Full Version : Auto resize iframe height

05-28-2009, 06:15 AM
Hi guys,
I've been stucking in this problem for months and couldn't find the solution yet. My index.php contains a header (php require) and an iframe so as to display the content. But when the content of the iframe is too long, it's naturally display a scrollbar beside that iframe, and it looks not nice. Now, i want the height of the iframe to be resized automatically, so, I think, the iframe's scrollbar will disappear and the overall scrollbar (I mean the scrollbar of the whole page, not just an iframe) will appear. That looks like AJAX. Thanks for helping.

05-29-2009, 12:15 AM
I have the same challenge and not found a solution yet! Maybe there isn't one.


06-04-2009, 01:42 AM
Try this. It works on my IE7 and FF. Please note that the called source must be the same domain. If you use your localhost server to call a remote site then it won't work.
<script type= "text/javascript">
window.onload = function() {
var newHeight = document.getElementById('glue').contentWindow.document.body.scrollHeight;
document.getElementById('glue').style.height = newHeight+10+"px";

<iframe id="glue" width="100%" src="http://huyenlam.com"></iframe>