English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Window screenTop property

JavaScript Window Object

screenTopRead-only property that returns the vertical distance (in pixels) from the top border of the user's browser viewport to the top of the screen.

The screenTop property is an oldscreenYAlias of the property.

Syntax:

window.screenTop
var win = window.open("", "popupWindow");
win.document.write("<p>This is 'popupWindow');
win.document.write("<br>ScreenLeft: " + win.screenLeft);
win.document.write("<br>ScreenTop: " + win.screenTop + "</p>
Test and See‹/›

Note: The screenLeft and screenTop properties are equal to the screenX and screenY properties.

Browser compatibility

The numbers in the table specify the first browser version that fully supports the screenTop property:

Property
screenTopIs64IsIs9

Technical details

Return value:Number of CSS pixels from the top edge of the browser viewport to the top of the screen

More examples

Returns the x and y coordinates of the new window relative to the screen:

var win = window.open("", "popupWindow", "left=500, top=350, width=300, height=200");
win.document.write("<p>This is 'popupWindow');
win.document.write("<br>ScreenLeft: " + win.screenLeft);
win.document.write("<br>ScreenTop: " + win.screenTop + "</p>
Test and See‹/›

Cross-browser solution (for IE8and earlier versions, use screenX and screenY):

var win = window.open("", "popupWindow", "left=500, top=350, width=300, height=200");
/* If the browser does not support screenLeft and screenTop, screenX and screenY can be used instead */
if (!window.screenLeft) {}}
   window.screenLeft = window.screenX;
   window.screenTop = window.screenY;
}
win.document.write("<p>This is 'popupWindow');
win.document.write("<br>ScreenLeft: " + win.screenLeft);
win.document.write("<br>ScreenTop: " + win.screenTop + "</p>
Test and See‹/›

Related References

Reference: Window (Window)window.screenLeft property

Reference: Window (Window)window.screenX property

Reference: Window (Window)window.screenY property

JavaScript Window Object