Click to See Complete Forum and Search --> : My automaticly resize iframe script won't work


Enselic
09-14-2003, 05:34 AM
I have a site with an iframe in which I show the chosen menuitem.

I have this script:
<script language="JavaScript" type="text/JavaScript">
<!--
function setIframe( html_document )
{
document.all( 'main' ).src = html_document;
document.all( 'main' ).style.height = document.all( 'main' ).body.clientHeight();
}
//-->
</script>

And the tag for clicking the menu items is like this:
<a href="javascript:setIframe( 'news.htm' )">News</a>

The frames content changes as it should, but I don't the the height to fit the contents of the iframe...

This problem is driving me nuts. If you know what I'm doing wroing, please tell me. I'm new to JavaScript if that isn't obvious if you refer to my posts in this forum...

Thank you.

swon
09-14-2003, 08:15 AM
Hi,

may this one can do it:

<script language="JavaScript" type="text/JavaScript">
<!--
function setIframe( html_document )
{
document.all.main.src = html_document;
document.all.main.style.height = document.all.main.document.body.scrollHeight;
}
//-->
</script>

And the tag for clicking the menu items is like this:
<a href="javascript:setIframe( 'news.htm' )">News</a>
<iframe name=main id=main src=file.html style="height:100;"></iframe>

Enselic
09-14-2003, 08:23 AM
According to w3c, you should have "" around your attribute values. I also heard that .all. was MSIE specific so I changed to getElementById() but that didn't work either.

swon
09-14-2003, 12:46 PM
I thought you knew that document.all is IE specific.

With document.getElementById() it looks something like this:

<script language="JavaScript" type="text/JavaScript">
<!--
function setIframe( html_document )
{
elm = document.getElementById('main');
elm.src = html_document;
elm.style.height = elm.document.body.scrollHeight;
}
//-->
</script>

And the tag for clicking the menu items is like this:
<a href="javascript:setIframe( 'news.htm' )">News</a>
<iframe name="main" id="main" src="neu.html" style="height:100;"></iframe>

(it works also without the "" in the attributes values)