# Rezsize Iframe to content.



## firestormer (Sep 16, 2005)

I have tried several methods of a result of a goolge search but none of them seem to work.

Now im sure your going to say drop the iframe but i see no other solution as i need to bring in content from a php page to a html page.

The last method i used was this but i just ended up with a frame about 4 times too small


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

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


```
<iframe src="menu.php" width="170" onload="calcHeight()" scrolling="no" name="Side" id="Side" align="left" valign="top" framespaceing="0" frameborder="0">
```
Any ideas


----------



## tomdkat (May 6, 2006)

Since you're calling "calcHeight()" in the onload event of the iframe element itself, you can pass "this" to calcHeight() and not fetch the element each time:

```
function calcHeight(frame)
{
  //find the height of the internal page
  var the_height = frame.contentWindow.document.body.scrollHeight;

  //change the height of the iframe
  frame.height = the_height;
}

<iframe src="menu.php" width="170" onload="calcHeight([b]this[/b])" scrolling="no" name="Side" id="Side" align="left" valign="top" framespaceing="0" frameborder="0">
```
What is the value of "the_height" using your original code above? I would add an alert window with the value of "the_height" so you can make sure the right value is coming back:

```
function calcHeight()
{
  //find the height of the internal page
  var the_height = document.getElementById('Side').contentWindow.document.body.scrollHeight;
 alert("Content height: "+the_height);
  //change the height of the iframe
  document.getElementById('Side').height = the_height;
}
```
Then, I would verify if the height reported matches the actual height of the iframe.

I don't know if using a CSS height would yield any better results or not.

Peace...


----------



## tomdkat (May 6, 2006)

Also, see if this helps.

Peace...


----------

