set height of iframe to height of content.

Discussion in 'HTML & Website Design' started by DanInManchester, Feb 16, 2010.

  1. #1
    I need my iframe to fit the content.

    The content may be several screens of content so I want the iframe to essentially act like a div so it doesn't scroll it just stretches to fit.

    Any ideas how to do this?
     
    DanInManchester, Feb 16, 2010 IP
  2. SpawnONE

    SpawnONE Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use CSS to set the height of the iframe to 100%... also the container of the iframe must have a fixed size in order to work in IE.
     
    SpawnONE, Feb 18, 2010 IP
  3. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    That only sets it to 100% of the parent doesn't it?
    I want it to be the height of the page that opens within it so it doesn't scroll.
     
    DanInManchester, Feb 18, 2010 IP
  4. SpawnONE

    SpawnONE Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well then you have to set the height of the iframe to the height of the page loaded in it... or use JavaScript to resize the iframe if you plan to load different pages.
     
    SpawnONE, Feb 18, 2010 IP
  5. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    so jquery could handle this I guess?
     
    DanInManchester, Feb 18, 2010 IP
  6. SpawnONE

    SpawnONE Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It depends on what you want to use. If you decide to use jQuery, you can animate the resizing which will make it more attractive.
     
    SpawnONE, Feb 18, 2010 IP
  7. Benjelliott

    Benjelliott Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    JavaScript can do it, but if you want it to be animated, go for jQuery.
     
    Benjelliott, Feb 18, 2010 IP
  8. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    DanInManchester, Feb 18, 2010 IP
  9. SpawnONE

    SpawnONE Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yes, that should work fine...
     
    SpawnONE, Feb 18, 2010 IP
  10. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    actually it looks simpler than i thought .... something like .....

    function setHeight(id)
    {

    e = document.getElementsById(id);

    if(e.contentDocument)
    {
    e.height = e.contentDocument.body.offsetHeight + 35;
    }
    else
    {
    e.height = e.contentWindow.document.body.scrollHeight;
    }

    }
     
    DanInManchester, Feb 18, 2010 IP