PDA

View Full Version : iFrame Auto Resize



SawnDiddle
07-13-2006, 02:25 AM
Ok, so I have the following script that resizes an iframe based on the content. The problem is that I only have it for IE. Can someone tell me how to get this to work in Firefox too?


<script language="JavaScript">
<!--
function calcHeight()
{
//find the height of the internal page
var the_height=
document.getElementById('main_div').contentWindow.
document.body.scrollHeight;

//change the height of the iframe
document.getElementById('main_div').height=
the_height;
}
//-->
</script>

jscheuer1
07-14-2006, 05:37 AM
See:

http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm

In the code for that script you will see how FF uses this syntax:


.contentDocument.body.offsetHeight

not the IE methods:


.contentWindow.document.body.scrollHeight;

as you used or:


.Document.body.scrollHeight

as used by the above linked script.

Also, just a little tip when working with iframes, it is important to treat them as objects sometimes and as elements other times.