Results 1 to 4 of 4

Thread: iframe autofit height

  1. #1
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool iframe autofit height

    I'm using code to bring in pages of various heights but standard widths under a banner/menu. i want them to be displayed without scroll bars beyond standard on side of browser. for the most part i've found code that mostly works, however it does not re-adjust itself down in size after finding a page of larger height, ie the height grows but does not shrink. i'm looking for a way to modify the code so that it either resets height to 0 before fetching the actual height of the loading page or some other method of dynamically alterning the height page not only up but also back down. here is the code i borrowed and used.


    //This part was put in the header

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

    //change the height of the iframe
    document.getElementById('the_iframe').height=
    the_height;
    }
    //-->



    //this is in the main body. picture above a menu option that uses the below script to load the page into the iframe and then the above caclheight to adjust the height setting. only it just adjusts up, not back down.

    <iframe name="the_iframe" onLoad="calcHeight();" scrolling="no" width="730" id="the_iframe" src="you_page.html" frameborder="0" allowtransparency="true"></iframe>

  2. #2
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default iframe autofit height

    ultron2099,
    have you found a solution yet? if not, what browser are you using?

  3. #3
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by fobos View Post
    ultron2099,
    have you found a solution yet? if not, what browser are you using?


    Still looking. I'm using Mozilla Firefox, but I would like to keep things as cross platform viable as possible. What I think I'm looking for is a way to have the value set to zero at the the start of the script. that way each page will be calculated freshly.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,375
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    I've found that with the various DOCTYPEs available, and the various browser's quirkiness as regards the now deprecated iframe element, and the possibility that the external page's height may not be as accessible (due to its layout) as one would want for something like this, it is all but impossible to come up with a solution to this issue other than one that is customized to your external content (which ideally should be standardized in some ways), and that includes some browser/feature detection for the purpose of tweaking the height for a given browser or feature set found in certain browsers.

    For some ideas, look here:

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

    and here:

    http://www.dynamicdrive.com/forums/s...384#post127384

    neither of which, in my opinion are truly cross browser or applicable in all situations, but that contain enough coding ideas for any clever person familiar with javascript to work out the sort of custom solution I refer to at the beginning of this post.
    - John
    ________________________

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

Tags for this Thread

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
  •