Get window location on the screen in Javascript in JavaScript

Description

The following code shows how to get window location on the screen in Javascript.

Example


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


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

Click to view the demo

The code above generates the following result.

Get window location on the screen in Javascript in JavaScript