Results 1 to 2 of 2

Thread: iFrame Auto Resize

  1. #1
    Join Date
    Nov 2005
    Posts
    40
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default iFrame Auto Resize

    Ok, so I have the following script that resizes an iframe based on the content. The problem is that I only have it for IE. Can someone tell me how to get this to work in Firefox too?

    Code:
    <script language="JavaScript">
    <!--
    function calcHeight()
    {
      //find the height of the internal page
      var the_height=
        document.getElementById('main_div').contentWindow.
          document.body.scrollHeight;
    
      //change the height of the iframe
      document.getElementById('main_div').height=
          the_height;
    }
    //-->
    </script>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    See:

    http://www.dynamicdrive.com/dynamici...iframessi2.htm

    In the code for that script you will see how FF uses this syntax:

    Code:
    .contentDocument.body.offsetHeight
    not the IE methods:

    Code:
    .contentWindow.document.body.scrollHeight;
    as you used or:

    Code:
    .Document.body.scrollHeight
    as used by the above linked script.

    Also, just a little tip when working with iframes, it is important to treat them as objects sometimes and as elements other times.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •