How to get length of document in an iframe

Discussion in 'Javascript' started by Asterbing, Jun 14, 2007.

  1. Asterbing

    Asterbing Guest

    I want to know the length in pixels of a document embedded in a iframe.
    The way I go seems to work under IE but not under Firefox (about other
    browsers I'll see later).

    Here is my page for testing :

    1) The page which will appear in the iframe is :

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>inside</title>
    <script type="text/javascript">
    function docsize(){
    alert(this.document.body.scrollHeight + "px");}
    </script>
    </head>
    <body bgcolor="white">
    <form action="" method="post">
    <input type="button" value="Size of Doc Inside" onclick="docsize();">
    </form>
    <p>ljlsqdjqlsd ljsqldjqs dlj lqsjkd lqsdkj lqskdjsq ldqsdlj lqsdkj
    qslkdj ql qsldjqs dlqs jdlqs dlqsdj qsldj qsl dqlsd sqld jsqld qsdqsl
    dlqs dqsl dlqs dlqs dlqsjd lqsd qsld qsdl qsdlqsj dlqsjd sqld qsld lsqd
    lqzd qsld qsldjqs dlqs dlqs dlqs dlqs dlqsd qsl dqs dlqsd qsld qsld qsld
    qsld qsld qsld qsl dsqld qsl dlqs dqsj dlqsd sqld qsld qsld qsljd qsldj
    qsld qsld jqsld qsld jqsl dqsjld qsld jqsl dsql djqsld jqsld qsld qsld
    qsl djqsld qsld qsldjqs ldj qsdl
    <br><br>
    That's all !</p>
    </body>
    </html>

    2) The document with the iframe which will contains the first doc

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>iFrame resize</title>
    <script type="text/javascript">
    function resize(h)
    {
    var f = document.getElementById("container");
    f.setAttribute("height", h);
    }
    </script>
    </head>
    <body style="background: purple">
    <form action="" method="post">
    <input type="button" value="500" onclick="resize(500);">
    <input type="button" value="250" onclick="resize(250);">
    </form>
    <div style="position: absolute; visibility: visible; border: dotted
    white">
    <iframe id="container" width="731" height="100" src="some.htm"
    scrolling="no" style="border: thin"></iframe></div>
    </body>
    </html>


    So, to test, just do this :
    1) clic to knwow current size
    2) clic to resize the iframe
    3) the size of doc inside shouldn't change with iframe size (I don't
    want the iframe size, but the size of document inside)

    It works under IE, not Firefox 1.5 under Windows

    How to do it works ?
    Asterbing, Jun 14, 2007
    #1
    1. Advertising

  2. Asterbing

    Asterbing Guest

    In article <>,
    says...
    > I want to know the length in pixels of a document embedded in a iframe.
    > The way I go seems to work under IE but not under Firefox (about other
    > browsers I'll see later).
    >
    > Here is my page for testing :
    >
    > 1) The page which will appear in the iframe is :
    >
    > <html>
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    > <title>inside</title>
    > <script type="text/javascript">
    > function docsize(){
    > alert(this.document.body.scrollHeight + "px");}
    > </script>
    > </head>
    >


    OK, I've changed the scrollHeight with offsetHeight and it works for
    Firefox 1.5 (not tested in 2.0 : if someone can tel me)

    So, now, I would like it works for Netscape and Mozilla. So, I've tried
    with "this.document.documentElement.scrollHeight", but I fall down in
    same problem as the was I had with Firefox.

    So, what's the good expression for Netscape and its derivated browsers ?

    After I will wish to know for the browsers used under Linux : Konqueror
    and others you'll tell me (I don't use Linux)...
    Asterbing, Jun 14, 2007
    #2
    1. Advertising

  3. Asterbing

    The Magpie Guest

    Asterbing wrote:
    >
    > OK, I've changed the scrollHeight with offsetHeight and it works for
    > Firefox 1.5 (not tested in 2.0 : if someone can tel me)
    >

    Purely personally, my first port of call would have been to not use an
    <iframe> at all. It isn't really needed anyway and I have to say I
    simply could not see why you had gone that route at all.
    The Magpie, Jun 15, 2007
    #3
    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. Mitchua
    Replies:
    5
    Views:
    2,713
    Eric J. Roode
    Jul 17, 2003
  2. M. Clift
    Replies:
    8
    Views:
    405
    M. Clift
    Aug 19, 2004
  3. Replies:
    0
    Views:
    486
  4. Daedalous
    Replies:
    3
    Views:
    660
    Daedalous
    Jan 16, 2004
  5. Nathan Carr
    Replies:
    0
    Views:
    259
    Nathan Carr
    Sep 17, 2004
Loading...

Share This Page