Window screenLeft and screenTop Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window screenLeft screenTop


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>
function myFunction() {/*from   ww w  . j a  v a2s  .c o m*/
    var myWindow ="", "myWin");
    myWindow.document.write("<p>This is 'myWin'");
    myWindow.document.write("<br>ScreenLeft: " + myWindow.screenLeft);
    myWindow.document.write("<br>ScreenTop: " + myWindow.screenTop + "</p>");

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


Related Tutorials