Click to See Complete Forum and Search --> : Controlling an iframe's height


Oahgneg
04-25-2008, 12:42 PM
How do I control the height of an iframe based on the content of its
src? Do I use CSS/<div> or Javascript?

KDLA
04-25-2008, 01:09 PM
"based on the content of its src?"

If the source has a static height, you can use CSS.
<iframe style="height: 400px;">
</iframe>

Oahgneg
04-25-2008, 01:18 PM
But what if it doesn't?

If it does have a static height, I wouldn't need to use the CSS; I'd just have <iframe height= "400">

KDLA
04-25-2008, 01:22 PM
Is the target page on your server, or is it someplace else?

Oahgneg
04-25-2008, 01:32 PM
Both are on the same server.

Miracle_Men
04-28-2008, 08:32 AM
Above head the following code

<script>
function resizeMe(obj)
{
//docHeight = pages.document.body.scrollHeight
if (document.compatMode != 'CSS1Compat')
{
docHeight = document.getElementById('pages').contentWindow.document.documentElement.scrollHeight;
} else
{
docHeight = document.getElementById('pages').contentWindow.document.body.scrollHeight;
}


obj.style.height = docHeight + 'px';
}
</script>

Code for the iframe:
<iframe id="pages" name="pages" onload="resizeMe(this);"></iframe>

Miracle_Men