Is it possible to get document size?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Captain Dondo

    Is it possible to get document size?

    Is it possible to get the actual document size? Not the window size, but
    the actual rendered document size, which in my case is bigger than the
    window.

    I am trying to set up a form entry system where the user scrolls by the
    UP and DOWN keys. The idea is to keep as much context on the screen.

    Say the form has 15 lines, and 7 are displayed. The user starts on line
    1, at the top of the screen. The text on the screen stays fixed, until
    the user gets to the center of the page (line 4) and then scrolls one
    line at a time to always keep the current line centered, until the user
    gets to line 11, at which point the last 7 lines are displayed, and the
    screen stops scrolling...

    Does that make any sense? Basically, since the user probably wants to
    refer to the lines that are both above and below the current line, I
    want to keep the current line centered as much as possible....

    So I am thinking of retrieving the size of the entire document, then the
    size of the display window, and then calculating the percentage of the
    document that is displayed, and scrolling a certain percentage with each
    line....

    Any suggestions?

    --Yan
  • Lasse Reichstein Nielsen

    #2
    Re: Is it possible to get document size?

    Captain Dondo <yan@NsOeSiPnAe Mr.com> writes:
    [color=blue]
    > Is it possible to get the actual document size? Not the window size,
    > but the actual rendered document size, which in my case is bigger than
    > the window.[/color]

    Not consistently, but most modern browsers accept:
    document.docume ntElement.offse tWidth
    and
    document.docume ntElement.offse tHeight
    (You should be in standards mode to guarantee that the documentElement
    exists, otherwise you might get the result from document.body).

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Captain Dondo

      #3
      Re: Is it possible to get document size?

      Lasse Reichstein Nielsen wrote:[color=blue]
      > Captain Dondo <yan@NsOeSiPnAe Mr.com> writes:
      >
      >[color=green]
      >>Is it possible to get the actual document size? Not the window size,
      >>but the actual rendered document size, which in my case is bigger than
      >>the window.[/color]
      >
      >
      > Not consistently, but most modern browsers accept:
      > document.docume ntElement.offse tWidth
      > and
      > document.docume ntElement.offse tHeight
      > (You should be in standards mode to guarantee that the documentElement
      > exists, otherwise you might get the result from document.body).
      >
      > /L[/color]
      Hah! Googling on documentElement found this:



      For posterity....

      Comment

      • TheBagbournes

        #4
        Re: Is it possible to get document size?

        Lasse Reichstein Nielsen wrote:[color=blue]
        > Captain Dondo <yan@NsOeSiPnAe Mr.com> writes:
        >[color=green]
        >> Is it possible to get the actual document size? Not the window size,
        >> but the actual rendered document size, which in my case is bigger than
        >> the window.[/color]
        >
        > Not consistently, but most modern browsers accept:
        > document.docume ntElement.offse tWidth
        > and
        > document.docume ntElement.offse tHeight
        > (You should be in standards mode to guarantee that the documentElement
        > exists, otherwise you might get the result from document.body).
        >
        > /L[/color]

        That does not do it. Try creating a very wide element that overflows the
        window. In that case document.docume ntElement.offse tWidth returns the
        window width.

        I scrabbled around this for a while because I wanted to make a "dialog
        box" (which was in fact an absolutely positioned div) "modal". So I
        created a 0% opaque, full sized div to sit over the document, but under
        the "dialog box" (I had to use opacity to allow the document to show
        through because if I set the background-color to transparent, IE didn't
        acknowledge that it was there, and allowed user interaction with the
        underlying document!!)

        So this blocker had to be full size.

        I don't have the code to hand, it's at work. I'll post it on Monday.

        ExG

        Comment

        • TheBagbournes

          #5
          Re: Is it possible to get document size?

          Lasse Reichstein Nielsen wrote:[color=blue]
          > Captain Dondo <yan@NsOeSiPnAe Mr.com> writes:
          >[color=green]
          >> Is it possible to get the actual document size? Not the window size,
          >> but the actual rendered document size, which in my case is bigger than
          >> the window.[/color]
          >
          > Not consistently, but most modern browsers accept:
          > document.docume ntElement.offse tWidth
          > and
          > document.docume ntElement.offse tHeight
          > (You should be in standards mode to guarantee that the documentElement
          > exists, otherwise you might get the result from document.body).
          >
          > /L[/color]

          I found my code. It was the width it was having trouble with. If there
          was a very wide element in the document, then
          document.docume ntElement.offse tWidth did not work - just returned the
          viewport width. I used

          fcl.util.getDoc umentWidth = function()
          {
          if (document.body. scrollWidth)
          return document.body.s crollWidth;
          var w = document.docume ntElement.offse tWidth;
          if (window.scrollM axX)
          w += window.scrollMa xX;
          return w;
          };

          fcl.util.getDoc umentHeight = function()
          {
          if (document.body. scrollHeight)
          return document.body.s crollHeight;
          return document.docume ntElement.offse tHeight;
          };

          Comment

          Working...