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

Discussion in 'Javascript' started by Dave, Oct 24, 2006.

  1. Dave

    Dave Guest

    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
     
    Dave, Oct 24, 2006
    #1
    1. Advertising

  2. Dave

    Dave Guest

    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.scrollHeight;

    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
     
    Dave, Oct 24, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dennis Strickland via .NET 247

    How to autosize the row heigth in a Datagrid

    Dennis Strickland via .NET 247, Jun 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,370
    Uri Dor
    Jun 15, 2004
  2. raymond chiu

    set autosize of datagrid to no

    raymond chiu, Dec 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,726
    Christopher Reed
    Dec 29, 2005
  3. Jeff

    newbie: autosize

    Jeff, Jul 14, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,873
  4. =?Utf-8?B?U0FM?=

    How do you autosize a Table Cell?

    =?Utf-8?B?U0FM?=, Aug 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    14,500
    John Timney \(MVP\)
    Aug 10, 2006
  5. Daedalous
    Replies:
    3
    Views:
    754
    Daedalous
    Jan 16, 2004
Loading...

Share This Page