Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Iframe Auto Re-Size

  1. #1
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Question Iframe Auto Re-Size

    Sup everyone

    I'm trying to find a script that will automatically resize the height of an iframe depending on the document it contains. I found the script here:

    Code:
    <!--
    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;
    }
    //-->
    The only problem is that although it gets larger when the page changes, it doesn't get smaller. Any one know how to fix this???

  2. #2
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Question

    Are you serious?! Nobody knows how to do this???

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,997
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    Most folks who know anything about it don't want to touch this sort of question. The iframe is non-standard. As such any scheme for this sort of thing varies by browser, and is also subject to a high degree of influence from the markup on both the top page and the page in the iframe. This too varies by browser. This is not to say that it couldn't be worked out for a specific case, but it is also highly likely that there are numerous cases where it cannot be.

    Generally, the mission is to import content to the top page without refreshing the top page. AJAX, with all its issues surrounding any javascript that you want to run against the imported content, is a much better choice for that.
    - John
    ________________________

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

  4. #4
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    You're probably right... but this is really important. you have any idea where i could get help with this?

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,997
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    Well, as I say, iframe would be far from my first choice for this. Instead of asking for:

    a script that will automatically resize the height of an iframe depending on the document it contains
    Answer me this. Why do you want that? What are you trying to do that makes you think that you need that?
    - John
    ________________________

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

  6. #6
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    Well, my sites uses an iframe right in the middle of the page. its the center of the site. the reason i want it to change height is because all of my other pages are viewed from it, some of which a kinda long. it is distracting and doesnt look good with the scrollbar either.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,997
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    Sounds like you are locked into an archaic and non-standard setup.
    - John
    ________________________

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

  8. #8
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    What do you think i should do?

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,997
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    Well, and my apologies if this or anything I've already said sounds harsh, IMO iframe is questionable at best. It's OK, I guess, and even I will use it for one off sort of things. By one off (in this case) I mean something that isn't crucial for the site. And more to the point, one off of the site. Like something that pops up if supported that also has a fall back if the iframe and/or its content are not supported.

    I believe this is the general consensus on this issue with folks who do a lot or even some professional coding. If not, then the consensus would likely be to avoid iframe like the plague.

    From what you've said so far, in order to follow either of these philosophies would probably require a major redesign. Are you prepared for that if it comes to it?

    Anyways, most of what iframe is generally used for when it is used as extensively as you seem to be indicating it is used on your site can be accomplished with one or a combination of the following (in no particular order):

    • AJAX
    • Server side code
    • Separate pages


    There may be other approaches. To best tell what might work with your site, I would need more than:

    my sites uses an iframe right in the middle of the page. its the center of the site
    to go on.

    Is this more than one site? If so how many? Can you provide a link to the site (or if more than one, to one of the sites that is the most basic and typical in its use of iframe)?

    Answer those three questions, and if the answer to the last one (providing a link) is yes, please do so.

    Then I would be better able to solve, or at least offer ideas to solve things without iframe.

    One other bit of information I would need is whether or not you have server side coding available on the server(s) you are trying this on. Do you?
    - John
    ________________________

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

  10. #10
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    sorry, that was a typo... it is only one site. also, i can't provide a link cause its not up yet.

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
  •