Window screenLeft and screenTop Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window screenLeft screenTop

Description

The screenLeft and screenTop properties returns the x (horizontal) and y (vertical) coordinates of the window relative to the screen.

Return Value

A Number, representing the horizontal and vertical distance of the window relative to the screen, in pixels

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {/*from   ww 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>

Related Tutorials