The screenLeft
and screenTop
properties
returns the x and y coordinates of the
window relative to the screen.
For Firefox, use "window.screenX" and "window.screenY".
screenLeft and screenTop |
Yes | Yes | No | Yes | Yes |
window.screenLeft window.screenTop
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 a v a2s.c o m-->
var myWindow = window.open("", "myWin");
myWindow.document.write("<p>This is 'myWin'");
myWindow.document.write("<br>ScreenLeft: " + myWindow.screenLeft);
myWindow.document.write("<br>ScreenTop: " + myWindow.screenTop + "</p>");
}
</script>
</head>
<body>
<button onclick="myFunction()">Open "myWin"</button>
</body>
</html>
The code above is rendered as follows: