The screenX
and screenY
properties
returns the x and y coordinates of the window relative to the screen.
screenX and screenY |
Yes | 9.0 | Yes | Yes | Yes |
window.screenX window.screenY
The horizontal and vertical distance of the window relative to the screen.
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: