Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > iframe autosize problem in firefox. Ok in IE. Help!

Reply
Thread Tools

iframe autosize problem in firefox. Ok in IE. Help!

 
 
Dave
Guest
Posts: n/a
 
      10-24-2006
Usual apologies if this is old territory.

I'm resizing a bunch of iframes on a page to the height of their
contained documents. Some of the contained documents contain IMG tags.
On IE this doesn't cause a problem and the resize works correctly. On
Firefox, if an image extends below the last line of text in the
document, that bit gets chopped off. In other words, the returned
document height doesn't allow for the image.

My code for resizing an Iframe is:

function adjustIFrameSize (iframe)
{
if ( iframe.contentDocument ) // firefox
{
iframe.height = iframe.contentDocument.height;
}
else // IE
{
iframe.style.height =
iframe.contentWindow.document.body.scrollHeight;
}

}

Can someone tell me how I can modify the firefox line to make it do the
job correctly.

Many thanks.

Dave

 
Reply With Quote
 
 
 
 
Dave
Guest
Posts: n/a
 
      10-24-2006
I've found the answer so I thought I'd post it here for reference.

First, wait for all the iframes to load. In other words, call an onload
function in the body tag.

In that function, set each iframe height as follows:

iframe.height = iframe.contentDocument.documentElement.scrollHeigh t;

This works great on firefox.

Dave wrote:
> Usual apologies if this is old territory.
>
> I'm resizing a bunch of iframes on a page to the height of their
> contained documents. Some of the contained documents contain IMG tags.
> On IE this doesn't cause a problem and the resize works correctly. On
> Firefox, if an image extends below the last line of text in the
> document, that bit gets chopped off. In other words, the returned
> document height doesn't allow for the image.
>
> My code for resizing an Iframe is:
>
> function adjustIFrameSize (iframe)
> {
> if ( iframe.contentDocument ) // firefox
> {
> iframe.height = iframe.contentDocument.height;
> }
> else // IE
> {
> iframe.style.height =
> iframe.contentWindow.document.body.scrollHeight;
> }
>
> }
>
> Can someone tell me how I can modify the firefox line to make it do the
> job correctly.
>
> Many thanks.
>
> Dave


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you autosize a Table Cell? =?Utf-8?B?U0FM?= ASP .Net 1 08-10-2006 06:23 PM
newbie: autosize Jeff ASP .Net 3 07-14-2006 05:57 PM
set autosize of datagrid to no raymond chiu ASP .Net 1 12-29-2005 04:23 AM
How to autosize the row heigth in a Datagrid Dennis Strickland via .NET 247 ASP .Net 1 06-15-2004 11:42 AM
Get form values from iframe (1) to iframe (2) inside a layer in iframe (1) Daedalous Javascript 3 01-16-2004 11:08 AM



Advertisments