get the actual with and height of a document's content

Discussion in 'Javascript' started by juergen.riemer@chello.at, Apr 16, 2006.

  1. Guest

    Hi all,

    I want to get the actual dimensions of a document's content, not the
    body's width/height. I want to do this to be able to resize an iframe
    element in which this document resides to exactly the dimensions of the
    text/content of this source.
    My quick hack would be the code below, but it seems to be somewhat
    wild.. is there a more elegant way to solve this problem?

    greetz

    mord
    ----

    <html>
    <head>
    <script>
    onload = function(){
    var oBodyContent = document.body.innerHTML;
    var oWrapper = document.createElement("DIV");
    oWrapper.style.position = "absolute";
    oWrapper.style.top = "0px";
    oWrapper.style.visibility = "hidden";
    var oTable = document.createElement("TABLE");
    var oTBody = document.createElement("TBODY");
    var oTRow = document.createElement("TR");
    var oTData = document.createElement("TD");
    oTRow.appendChild(oTData);
    oTBody.appendChild(oTRow);
    oTable.appendChild(oTBody);
    oWrapper.appendChild(oTable);
    document.body.appendChild(oWrapper);
    oTData.innerHTML = oBodyContent;
    alert(oTable.offsetWidth+' '+oTable.offsetHeight);
    oWrapper.parentNode.removeChild(oWrapper);
    }
    </script>
    </head>

    <body>
    blafasel <br>
    blafasel <br>
    blafasel <br>
    </body>
    </html>
     
    , Apr 16, 2006
    #1
    1. Advertising

  2. wrote:

    > I want to get the actual dimensions of a document's content, not the
    > body's width/height. I want to do this to be able to resize an iframe
    > element in which this document resides to exactly the dimensions of
    > the text/content of this source.


    No, you do not want that.

    However, you will recognize that even if the displayed resource is not
    markup, HTML markup is used by browsers to display the content. So there
    is always a `html' and a `body' element.

    > My quick hack would be the code below, but it seems to be somewhat
    > wild.. is there a more elegant way to solve this problem?


    <URL:http://www.quirksmode.org/viewport/compatibility.html>


    PointedEars
     
    Thomas 'PointedEars' Lahn, Apr 16, 2006
    #2
    1. Advertising

  3. optimistx Guest

    "Thomas 'PointedEars' Lahn" <> kirjoitti viestissä
    news:...
    > wrote:
    >
    > > I want to get the actual dimensions of a document's content, not the
    > > body's width/height. I want to do this to be able to resize an iframe
    > > element in which this document resides to exactly the dimensions of
    > > the text/content of this source.

    >
    > No, you do not want that.

    ....

    I think I wanted to dimension an iframe to accommodate the contents without
    scrollbars. But alas, somebody knows, that I did not want that... :)

    I want to draw a circle with three corners. I want that.
     
    optimistx, Apr 16, 2006
    #3
  4. Guest

    Another successful usenet posting! ;)

    Three cheers to anonymous help and the power of newsgroups!
     
    , Apr 16, 2006
    #4
  5. Guest

    > I think I wanted to dimension an iframe to accommodate the contents without
    > scrollbars. But alas, somebody knows, that I did not want that... :)


    Your are right, I do not want to but was given a task by my supervisor.
    Scrollbars are not an option for this application (eventhough it is B2B
    with a defined system there would be other options I'd like more)

    > I want to draw a circle with three corners. I want that.


    Really do you want to? This would be an interesting academic question,
    same might go with my initial problem..

    Thanks in any case

    greetz

    mord
     
    , Apr 17, 2006
    #5
  6. Guest

    As for me wanting to do this.. I was given the order to find a solution
    (for an intranet app, defined system).

    To get the according height is not of a problem, but how to get
    information on the width? Any idea more elegant than the existing?

    BTW: Thanks for the link, PPK is in my bookmarks for years though ;)

    greetz

    mord
     
    , Apr 17, 2006
    #6
    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. Kepler
    Replies:
    12
    Views:
    370
    Richard Cornford
    Sep 20, 2004
  2. Pugi!
    Replies:
    5
    Views:
    178
  3. Netx
    Replies:
    8
    Views:
    232
    dhtml
    Dec 13, 2008
  4. r_honey
    Replies:
    23
    Views:
    463
    dhtml
    Dec 22, 2008
  5. Martin Molema
    Replies:
    2
    Views:
    159
    dhtml
    Jan 11, 2009
Loading...

Share This Page