Forum Moderators: open

Message Too Old, No Replies

Setting IFRAME height with scrollHeight

I'm close but with mulitple iframes it doesn't work

         

kevinkp7

8:17 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



Here's an example of what I've done. There's a little basic php in there - hope that doesn't throw you off.

Parent Document


<body onload="loadFrames();">

<div id="0">
</div>

<div id="1">
</div>

<div id="2">
</div>

<div id="3">
<iframe name="f3" style="width:760px;" src="file.php?id=3" onload="javascript:fixFrame3();"></iframe>
</div>

<div id="frameHeight"></div>

<script type="text/javascript">

var inner=new Array();
<?php for($c=0;$c<3;$c++): ?>

//make 3 iframes
inner[<?php echo $c; ?>]='<iframe name="f<?php echo $c; ?>" style="width:760px;" src="file.php?id=<?php echo $c; ?>" onload="javascript:fixHeight(<?php echo $c; ?>);"></iframe>';

<?php endfor; ?>

function loadFrames() {
for(i=0;i<3;i++){
document.getElementById(i).innerHTML = inner[i];
document.getElementById("f"+i).style.height = window.frames[i].document.getElementById("wrap"+i).scrollHeight + "px";
}
}

function fixFrame3() {
document.getElementById("frameHeight").innerHTML = window.f3.document.getElementById("wrap3").scrollheight + " px";
}

</script>
</body>

file.php


<?php
// get id from src path
$id = $_GET['id'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

<div id="wrap<?php echo $id; ?>">

<?php if($id==0): ?>
<img src="http://example.info/images/photo/misc/drink.jpg" />
<?php elseif($id==1): ?>
<img src="http://example.info/images/photo/misc/lunch.jpg" />
<?php elseif($id==2): ?>
<img src="http://example.info/images/photo/circle/log.jpg" />
<?php elseif($id==3): ?>
<img src="http://example.info/images/photo/circle/wooden.jpg" />
<?php endif; ?>

</div><!-- end wrap -->

</body>
</html>

any thoughts?

[edited by: coopster at 9:13 pm (utc) on Mar. 19, 2009]
[edit reason] please use example.com, thanks! [/edit]

whoisgregg

8:45 pm on Mar 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, kevinkp7!

What error are you getting? Or, if you don't have an error, how is it not achieving your desired effect?

The php mixed in won't throw us off, but I think we'll need a bit more information to be helpful. :)

kevinkp7

8:51 pm on Mar 26, 2009 (gmt 0)

10+ Year Member



sorry - i didn't know how to set the Iframe height dynamically in this particular example.

however, i found a much better work around and it's no longer an issue - i'll un-new this post...

whoisgregg

9:08 pm on Mar 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted, Kevin. :)