PDA

View Full Version : Resizing an iframe everytime a new page is loaded.



Shawn05
12-18-2005, 07:41 PM
HI there. I am looking to try and figure out how to change the height of an iframe everytime a new page is loaded inside of it. I currently can change it onLoad of the initial iframe but not after something else is loaded inside of it. Here is what I currently have


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

//change the height of the iframe
document.getElementById('iframe').height=
the_height;

}
//-->
</script>

Then the actual iframe


<iframe onLoad="calcHeight();" width="600" id="iframe" src="somepage.php" scrolling="NO" frameborder="0" height="100">An iframe capable browser is required to view this web site.</iframe>

Any help would be great. Thank you.

Twey
12-18-2005, 10:00 PM
I don't think you can. I don't believe there's a handler associated with iframes for this eventuality. You'd just have to add the code to wherever the iframe-changing code is called from.

jscheuer1
12-18-2005, 11:14 PM
It is not considered W3C valid but, the three major browsers like it fine. See my "Iframe SSI script III" as first introduced here (http://www.dynamicdrive.com/forums/showpost.php?p=22387&postcount=17) and later modified for better behavior under Opera here (http://www.dynamicdrive.com/forums/showpost.php?p=22415&postcount=20). If you want a page that will validate, consider using DD's Iframe SSI script II (http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm) or wait for my next modification in which the onload event(s) will be added dynamically to the iframe(s), so as not to excite the W3C validator.

Shawn05
12-19-2005, 01:05 AM
works in firefox so it works for me. thank you.