viewport properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dean A. Hoover

    viewport properties

    Sorry if this is in a faq, I don't know where the
    faq is... How do I get the x, y, width, and
    height of the "viewport"? You know, the viewable
    window that may be scrolled. In cross browser fashion,
    of course.

    Thanks.
    Dean Hoover
  • RobG

    #2
    Re: viewport properties

    Dean A. Hoover wrote:
    [color=blue]
    > Sorry if this is in a faq, I don't know where the
    > faq is... How do I get the x, y, width, and
    > height of the "viewport"? You know, the viewable
    > window that may be scrolled. In cross browser fashion,
    > of course.
    >
    > Thanks.
    > Dean Hoover[/color]

    The FAQ is here:



    Item 4.9 should get you started...

    Comment

    • Dean A. Hoover

      #3
      Re: viewport properties

      RobG wrote:[color=blue]
      > Dean A. Hoover wrote:
      >[color=green]
      >> Sorry if this is in a faq, I don't know where the
      >> faq is... How do I get the x, y, width, and
      >> height of the "viewport"? You know, the viewable
      >> window that may be scrolled. In cross browser fashion,
      >> of course.
      >>
      >> Thanks.
      >> Dean Hoover[/color]
      >
      >
      > The FAQ is here:
      >
      > http://jibbering.com/faq/
      >
      > Item 4.9 should get you started...[/color]

      Thanks. In the combined code for Item 4.9, what does it
      mean if the last if statement is false? The variables do
      not get defined...

      Dean

      Comment

      • Michael Winter

        #4
        Re: viewport properties

        On Fri, 17 Sep 2004 13:25:25 GMT, Dean A. Hoover <dhxyz2010@yaho o.com>
        wrote:

        [snip]
        [color=blue]
        > Thanks. In the combined code for [FAQ] Item 4.9, what does it mean if
        > the last if statement is false? The variables do not get defined...[/color]

        Basically, yes. The variables will exist, but they won't have a value.
        However, I don't know how much chance there is of that happening. Most
        browsers follow either Microsoft or Netscape with regard to this sort of
        proprietary information.

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • Dean A. Hoover

          #5
          Re: viewport properties

          Michael Winter wrote:[color=blue]
          > On Fri, 17 Sep 2004 13:25:25 GMT, Dean A. Hoover <dhxyz2010@yaho o.com>
          > wrote:
          >
          > [snip]
          >[color=green]
          >> Thanks. In the combined code for [FAQ] Item 4.9, what does it mean if
          >> the last if statement is false? The variables do not get defined...[/color]
          >
          >
          > Basically, yes. The variables will exist, but they won't have a value.
          > However, I don't know how much chance there is of that happening. Most
          > browsers follow either Microsoft or Netscape with regard to this sort
          > of proprietary information.
          >
          > Mike
          >[/color]
          Hmmm. Then maybe I mistyped something. I transcribed the code I
          saw in the FAQ, slightly modified it to my liking, and stuffed
          it into an HTML page. On IE 6, the variables are undefined. Do
          you see what I did wrong? (works on mozilla)

          <html>
          <head>
          <script type="text/javascript">
          function x()
          {
          var winWidth;
          var winHeight;

          if (typeof window.innerWid th != 'undefined')
          {
          alert("A");
          winWidth = window.innerWid th;
          winHeight = window.innerHei ght;
          }
          else
          {
          alert("B");
          if (document.docum entElement &&
          (typeof document.docume ntElement.clien tWidth != 'undefined') &&
          (document.docum entElement.clie ntWidth != 0))
          {
          alert("C");
          winWidth = document.docume ntElement.clien tWidth;
          winHeight = document.docume ntElement.clien tHeight;
          }
          else
          {
          alert("D");
          if (document.body &&
          (typeof document.body.c lientWidth !=' undefined'))
          {
          alert("E");
          winWidth = document.body.c lientWidth;
          winHeight = document.body.c lientHeight;
          }
          }
          }

          window.status = winWidth + "," + winHeight;
          }

          document.onscro ll = x;
          x();
          </script>
          </head>
          <body>
          <table>
          <tr><td><img src="images/spacer.gif" width="500" height="500"></td></tr>
          </table>
          </body>
          </html>

          Comment

          • Michael Winter

            #6
            Re: viewport properties

            On Fri, 17 Sep 2004 14:11:02 GMT, Dean A. Hoover <dhxyz2010@yaho o.com>
            wrote:

            [snip]
            [color=blue]
            > Hmmm. Then maybe I mistyped something. I transcribed the code I saw in
            > the FAQ, slightly modified it to my liking, and stuffed it into an HTML
            > page. On IE 6, the variables are undefined. Do you see what I did wrong?
            > (works on mozilla)[/color]

            If what you posted is your exact code, then

            (typeof document.body.c lientWidth !=' undefined'))

            is the problem (from the last nested if statement). You need to remove the
            space preceeding "undefined" . That is:

            (typeof document.body.c lientWidth != 'undefined'))

            [snip]

            Hope that helps,
            Mike

            --
            Michael Winter
            Replace ".invalid" with ".uk" to reply by e-mail.

            Comment

            • Dean A. Hoover

              #7
              Re: viewport properties

              Thanks. Made that change but its still showing undefined,undef ined.
              Dean

              Michael Winter wrote:[color=blue]
              > On Fri, 17 Sep 2004 14:11:02 GMT, Dean A. Hoover <dhxyz2010@yaho o.com>
              > wrote:
              >
              > [snip]
              >[color=green]
              >> Hmmm. Then maybe I mistyped something. I transcribed the code I saw
              >> in the FAQ, slightly modified it to my liking, and stuffed it into an
              >> HTML page. On IE 6, the variables are undefined. Do you see what I
              >> did wrong? (works on mozilla)[/color]
              >
              >
              > If what you posted is your exact code, then
              >
              > (typeof document.body.c lientWidth !=' undefined'))
              >
              > is the problem (from the last nested if statement). You need to remove
              > the space preceeding "undefined" . That is:
              >
              > (typeof document.body.c lientWidth != 'undefined'))
              >
              > [snip]
              >
              > Hope that helps,
              > Mike
              >[/color]

              Comment

              • Michael Winter

                #8
                Re: viewport properties

                On Fri, 17 Sep 2004 14:32:14 GMT, Dean A. Hoover <dhxyz2010@yaho o.com>
                wrote:
                [color=blue]
                > Thanks. Made that change but its still showing undefined,undef ined.[/color]

                Sorry, I forgot to mention the x() call. In its location, the body of the
                document hasn't been loaded, so the dimensions can't be calculated. Call
                the function using the load intrinsic event

                <body ... onload="x();">

                or

                window.onload = x;

                and everything will be fine.

                [snipped top-post]

                Mike

                --
                Michael Winter
                Replace ".invalid" with ".uk" to reply by e-mail.

                Comment

                • Dean A. Hoover

                  #9
                  Re: viewport properties

                  Thanks Mike, that works. Now to figure out what properties
                  I need to look at to the the "viewport" x,y,width,heigh t, based
                  on where the browser window is scrolled to... I'm reading
                  through the O'Reilly Dynamic DHTML book, trying to find the
                  various ways these scroll properties are referred to.

                  Thanks.
                  Dean

                  Michael Winter wrote:[color=blue]
                  > On Fri, 17 Sep 2004 14:32:14 GMT, Dean A. Hoover <dhxyz2010@yaho o.com>
                  > wrote:
                  >[color=green]
                  >> Thanks. Made that change but its still showing undefined,undef ined.[/color]
                  >
                  >
                  > Sorry, I forgot to mention the x() call. In its location, the body of
                  > the document hasn't been loaded, so the dimensions can't be calculated.
                  > Call the function using the load intrinsic event
                  >
                  > <body ... onload="x();">
                  >
                  > or
                  >
                  > window.onload = x;
                  >
                  > and everything will be fine.
                  >
                  > [snipped top-post]
                  >
                  > Mike
                  >[/color]

                  Comment

                  • Yann-Erwan Perio

                    #10
                    Re: viewport properties

                    Dean A. Hoover wrote:
                    [color=blue]
                    > How do I get the x, y, width, and
                    > height of the "viewport"?[/color]

                    You've already been pointed to the FAQ, however the code provided in 4.9
                    can be inaccurate in some situations; Richard Cornford's been writing a
                    more advanced version with a very solid logic, and has posted an early
                    release recently - AIUI it should be added as a FAQ note when the author
                    is satisfied with his tests.

                    The original code, which I believe you could be interested using, and a
                    slight modification later in the thread, can be found there:

                    <URL:http://groups.google.c om/groups?selm=chv 12l%24sjs%241%2 48302bc10%40new s.demon.co.uk>


                    Regards,
                    Yep.

                    Comment

                    • Dr John Stockton

                      #11
                      Re: viewport properties

                      JRS: In article <tPp2d.1983$yg. 603@twister.nyr oc.rr.com>, dated Fri, 17
                      Sep 2004 00:01:29, seen in news:comp.lang. javascript, Dean A. Hoover
                      <dhxyz2010@yaho o.com> posted :[color=blue]
                      >Sorry if this is in a faq, I don't know where the
                      >faq is... How do I get the x, y, width, and
                      >height of the "viewport"? You know, the viewable
                      >window that may be scrolled. In cross browser fashion,
                      >of course.[/color]

                      The newsgroup FAQ is posted to the newsgroup three times a week, in two
                      parts. It is also cited in posters' signatures, and frequently cited
                      specifically in replies. One should always read a newsgroup for a while
                      before posting to it.

                      --
                      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
                      Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
                      Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
                      No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                      Comment

                      • Dean A. Hoover

                        #12
                        Re: viewport properties

                        Excellent information. Thanks for the help!
                        Dean

                        Yann-Erwan Perio wrote:[color=blue]
                        > Dean A. Hoover wrote:
                        >[color=green]
                        >> How do I get the x, y, width, and
                        >> height of the "viewport"?[/color]
                        >
                        >
                        > You've already been pointed to the FAQ, however the code provided in 4.9
                        > can be inaccurate in some situations; Richard Cornford's been writing a
                        > more advanced version with a very solid logic, and has posted an early
                        > release recently - AIUI it should be added as a FAQ note when the author
                        > is satisfied with his tests.
                        >
                        > The original code, which I believe you could be interested using, and a
                        > slight modification later in the thread, can be found there:
                        >
                        > <URL:http://groups.google.c om/groups?selm=chv 12l%24sjs%241%2 48302bc10%40new s.demon.co.uk>
                        >
                        >
                        >
                        > Regards,
                        > Yep.[/color]

                        Comment

                        Working...