Possible to resize an Iframe to its content's height?

Discussion in 'Javascript' started by wolfing1@gmail.com, Mar 23, 2006.

  1. Guest

    Maybe this doesn't make any sense, but is it possible to dynamically
    resize an iframe to the height of its contained page? Something that
    works in Opera/Firefox/IE.
    I can resize it with a
    document.getElementById("frameItems").style.height = "200px" for
    example, but was wondering if I could access somehow the full size its
    inner page would take... which might not make much sense but still who
    knows.
     
    , Mar 23, 2006
    #1
    1. Advertising

  2. Guest

    Ian Collins wrote:
    > wrote:
    > > Maybe this doesn't make any sense, but is it possible to dynamically
    > > resize an iframe to the height of its contained page? Something that
    > > works in Opera/Firefox/IE.
    > > I can resize it with a
    > > document.getElementById("frameItems").style.height = "200px" for
    > > example, but was wondering if I could access somehow the full size its
    > > inner page would take... which might not make much sense but still who
    > > knows.
    > >

    > I haven't tried it, but can you use the size of the iframe's <body> element?
    >
    > --
    > Ian Collins.

    Made it work! What I did (copied from somewhere in the web):
    In the "inner" page, an onload like this:
    <body onload="parent.adjustIFrameSize(window);">

    And in the actual page a js function like this:
    function adjustIFrameSize(iframeWindow) {
    if (iframeWindow.document.height) {
    var iframeElement = document.getElementById ("frameItems");
    iframeElement.style.height = iframeWindow.document.height + 'px';
    iframeElement.style.width = iframeWindow.document.width + 'px';
    } else if (document.all) {
    var iframeElement = document.all["frameItems"];
    if (iframeWindow.document.compatMode &&
    iframeWindow.document.compatMode != 'BackCompat') {
    iframeElement.style.height =
    iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
    iframeElement.style.width =
    iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
    } else {
    iframeElement.style.height =
    iframeWindow.document.body.scrollHeight + 5 + 'px';
    iframeElement.style.width = iframeWindow.document.body.scrollWidth
    + 5 + 'px';
    }
    }
    }

    where frameItems is the name of the frame containing the page.
    Tested in IE, Firefox and Opera and works in all of them so good enough
    for me.
     
    , Mar 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. thunk
    Replies:
    1
    Views:
    359
    thunk
    Mar 30, 2010
  2. thunk
    Replies:
    0
    Views:
    536
    thunk
    Apr 1, 2010
  3. thunk
    Replies:
    14
    Views:
    659
    thunk
    Apr 3, 2010
  4. Replies:
    0
    Views:
    167
  5. visu
    Replies:
    3
    Views:
    178
    totalstranger
    Mar 1, 2007
Loading...

Share This Page