spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column29


Window and Page Scrolling Functions

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

DOCJSLIB Version 3.0 introduces four new functions that relate to the physical dimensions of the browser window and its relative position with respect to the top left corner of the page. These functions deal with four dimensions:

  • The window's width: The physical width of the browser window in pixels.
  • The window's height: The physical height of the browser window in pixels.
  • The page's right-scrolled portion: The size of the scrolled right portion of the page to the right. This is the distance in pixels between the left edge of window to the left edge of the page.
  • The page's down-scrolled portion. The size of the scrolled down portion of the page. This is the distance in pixels between the top edge of the window to the top edge of the page.

The getWindowWidth() function gets the window's width:

function docjslib_getWindowWidth() {
  if (NS4) {return window.innerWidth}
  else {return document.body.clientWidth}
}

Notice how Netscape Navigator stores the window width under the window object, while Internet Explorer stores it under the document.body object. Similarly, the getWindowHeight() function is defined as follows:

function docjslib_getWindowHeight() {
  if (NS4) {return window.innerHeight}
  else {return document.body.clientHeight}
}

The getPageScrollLeft() gets the size in pixels of the right-scrolled portion of the page:

function docjslib_getPageScrollLeft() {
  if (NS4) {return window.pageXOffset}
  else {return document.body.scrollLeft}
}

The matching getPageScroolTop() function gets the scrolled-down portion of the page:

function docjslib_getPageScrollTop() {
  if (NS4) {return window.pageYOffset}
  else {return document.body.scrollTop}
}

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Created: November 9, 1998
Revised: November 9, 1998

URL: http://www.webreference.com/js/column29/window.html