Javascript Reference - Window screenX and screenY Property








The screenX and screenY properties returns the x and y coordinates of the window relative to the screen.

Browser Support

screenX and screenY Yes 9.0 Yes Yes Yes

Syntax

window.screenX
window.screenY

Return Value

The horizontal and vertical distance of the window relative to the screen.





Example

The following code shows how to get the x and y coordinates of the new window relative to the screen.


<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {<!--from   w w w.  j  av a  2  s.co m-->
    var myWindow = window.open("", "myWin");
    myWindow.document.write("<p>This is 'myWin'");
    myWindow.document.write("<br>ScreenX: " + myWindow.screenX);
    myWindow.document.write("<br>ScreenY: " + myWindow.screenY + "</p>");
}
</script>
</head>
<body>

<button onclick="myFunction()">Open "myWin"</button>

</body>
</html>

The code above is rendered as follows: