Determining position of the browser window in JavaScript?

For various silly reasons, I'd like to be able to detect the rectangle of the browser window on screen. Title bar and all.

Is this possible, or is JavaScript limited to the view port of its page?

Edit: I may have been unclear, but view port is the portion of the page that's visible in the window. This may not be a term commonly used with browsers, but it's common in graphics.


Solution 1:

For standards compliant browsers:

X - window.screenX
Y - window.screenY

For IE:

X - window.screenLeft
Y - window.screenTop

Keep in mind, implementations vary. Beware of multi-monitor setups...

Solution 2:

Take a look at the following properties:

  • window.screen.height: Returns the height of the screen in pixels.
  • window.screen.top: Returns the distance in pixels from the top side of the current screen.
  • window.screen.width: Returns the width of the screen.
  • window.screen.left: Returns the distance in pixels from the left side of the main screen to the left side of the current screen.

(These won't give you the window size or position, but may allow you to correctly interpret them when operating on a system with multiple monitors)