最新的Web開發教程
 

窗口screenLeft和screenTop屬性

<窗口對象

返回新相對於屏幕窗口的X和Y坐標:

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>");
試一試»

更多"Try it Yourself"下面的例子。


定義和用法

的screenLeft和screenTop屬性返回X (horizontal)和y (vertical)相對於屏幕窗口的坐標。


瀏覽器支持

在表中的數字規定,完全支持該財產瀏覽器版本。

屬性
screenLeft 不支持
screenTop 不支持

Note:對於Firefox,用“ window.screenX ”和“ window.screenY(See "More Examples" for a cross-browser solution)


句法

window.screenLeft
window.screenTop

技術細節

返回值: 一個數字,表示在屏幕上相對的窗口的水平和垂直距離,以像素為單位

例子

更多示例

跨瀏覽器解決方案(using screenX and screenY for IE8 and earlier)

// Open a new window with a specified left and top position
var myWindow = window.open("", "myWin", "left=700, top=350, width=200, height=100");

/*
If the browser does not support screenX and screen Y,
use screenLeft and screenTop instead (and vice versa)
*/
var winLeft = myWindow.screenLeft ? myWindow.screenLeft : myWindow.screenX;
var winTop = myWindow.screenTop ? myWindow.screenTop : myWindow.screenY;

// Write the new window's x and y coordinates relative to the screen
myWindow.document.write("<p>This is 'myWin'");
myWindow.document.write("<br>Horizontal: " + winLeft);
myWindow.document.write("<br>Vertical: " + winTop + "</p>");
試一試»

<窗口對象