Forum Moderators: open

Message Too Old, No Replies

iframe auto resize in Safari

         

westbrookmajor

7:30 pm on Jan 4, 2010 (gmt 0)

10+ Year Member



This code is working great in FF and IE but not Safari ... Could someone help please?

<script language="javascript">
<!--
function calcHeight()
{
var the_height=
document.getElementById('submit_frame').contentWindow.
document.body.scrollHeight;

document.getElementById('submit_frame').style.height=
(the_height+10)+"px";
}
//-->
</script>

<iframe src="eew/index.html" onLoad="calcHeight();" scrolling="no" id="submit_frame" width="100%" frameborder="0">

whoisgregg

11:27 pm on Jan 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, westbrookmajor!

Safari doesn't use the .contentWindow property. Instead you can use .contentDocument. Something like this should do the trick across all browsers:

 var the_iframe = document.getElementById('submit_frame');
var the_document = (the_iframe.contentWindow ¦¦ the_iframe.contentDocument);
if(the_document.document) the_document = the_document.document;
var the_height= the_document.body.scrollHeight;