Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining position of the browser window in JavaScript?

Tags:

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.

like image 477
Allain Lalonde Avatar asked Feb 02 '09 17:02

Allain Lalonde


People also ask

What is screenX in JavaScript?

The screenX property returns the horizontal coordinate (according to the users computer screen) of the mouse pointer when an event was triggered. Tip: To get the vertical coordinate (according to the screen) of the mouse pointer, use the screenY property. Note: This property is read-only.

How do you find the coordinates of an element?

jQuery . offset() will get the current coordinates of the first element, or set the coordinates of every element, in the set of matched elements, relative to the document.

What is window screenX?

Definition and Usage The screenX property returns the x (horizontal) coordinate of a window, relative to the screen.


1 Answers

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...

like image 100
Shog9 Avatar answered Sep 20 '22 02:09

Shog9