Get window location on the screen in Javascript

Window location

The following code determines the left and top positions of the window across browsers:

Example


<!DOCTYPE HTML> 
<html> 
<body> 
<script type="text/javascript"> 
var leftPos = (typeof window.screenLeft == "number") ? 
                     window.screenLeft : 
                     window.screenX; <!--from w  w  w. ja  v a2s . c  o m-->
var topPos = (typeof window.screenTop == "number") ? 
                     window.screenTop : 
                     window.screenY; 
document.writeln(leftPos);
document.writeln(topPos);


</script> 
</body> 
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window