Dynamic resizing of iframes based on content height

Discussion in 'Javascript' started by Peter, Apr 29, 2005.

  1. Peter

    Peter Guest

    Hi,

    Does anyone know of how I could dynamically resize an iframe based on
    the content's height (for IE) so that no scrollbar appears for the iframe?
    The content will be from a different domain. I have searched on the web and
    have seen solution like this

    <script>
    function resize() {
    var oframe = document.getElementById("frameID");

    //***
    //var odoc = oframe.document; //(1)
    var odoc = oframe.Document; //(2)

    var obody = odoc.body;

    oframe.height = obody.scrollHeight;
    }
    </script>

    The html :
    <iframe onload="resize()" src=http://different.comain.content border="0"
    ....... > </iframe>

    I have seen 2 solutions on the web, the only difference being lines (1) and
    (2) get substitued.
    My browser is version IE 6.

    It seems that the solution with line (2) works perfectly when the content is
    from the same domain but gets a Permission Error if the domain is different.

    When the content is from a different domain solution (1) does not give
    Permission error, but instead the scrollHeight is significantly smaller
    than the actual content. Even if the content is from the same domain it
    still gives the wrong size.

    So my question is
    1) What is the difference between oframe.document and oframe.Document, why
    does it give different results?

    2) More importantly, how can I dynamically adjust the iframe size based on
    the content height from a different domain?
    Peter, Apr 29, 2005
    #1
    1. Advertising

  2. Peter wrote:

    > Does anyone know of how I could dynamically resize an iframe based on
    > the content's height (for IE) so that no scrollbar appears for the iframe?
    > The content will be from a different domain. [...]


    The Same Origin Policy prevents this almost certain violation of author's
    rights. Your goal would be a contradiction to the purpose of an iframe
    anyway.


    PointedEars
    Thomas 'PointedEars' Lahn, May 8, 2005
    #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. alejandro.rivero

    ... and resizing IFRAMEs

    alejandro.rivero, Nov 7, 2003, in forum: Javascript
    Replies:
    0
    Views:
    67
    alejandro.rivero
    Nov 7, 2003
  2. visu
    Replies:
    3
    Views:
    161
    totalstranger
    Mar 1, 2007
  3. laredotornado

    Setting height = 100% for iframes

    laredotornado, Jan 27, 2009, in forum: Javascript
    Replies:
    0
    Views:
    98
    laredotornado
    Jan 27, 2009
  4. Pil (Trustworthy from Experience)

    Resizing a div by resizing its borders

    Pil (Trustworthy from Experience), Apr 18, 2009, in forum: Javascript
    Replies:
    9
    Views:
    328
    Proper
    Apr 21, 2009
  5. Proper
    Replies:
    0
    Views:
    184
    Proper
    Apr 18, 2009
Loading...

Share This Page