Window screenLeft 和 screenTop 屬性
Window 對象定義和用法
screenLeft和screenTop屬性返回窗口相對于屏幕的X和Y坐標。
語法
window.screenLeft
window.screenTop
window.screenTop
瀏覽器支持
所有主要瀏覽器都支持pageXOffset和pageYOffset屬性,F(xiàn)irefox除外。
注意: Firefox 瀏覽器請使用 "window.screenX" and "window.screenY"。
實例
實例
返回新窗口相對于屏幕的X和Y坐標:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</title>
<script>
function openWin(){
myWindow=window.open('','');
myWindow.document.write("<p>這是'我的窗口'");
myWindow.document.write("<br>ScreenLeft: " + myWindow.screenLeft);
myWindow.document.write("<br>ScreenTop: " + myWindow.screenTop + "</p>");
}
</script>
</head>
<body>
<input type="button" value="打開 '我的窗口'" onclick="openWin()">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</title>
<script>
function openWin(){
myWindow=window.open('','');
myWindow.document.write("<p>這是'我的窗口'");
myWindow.document.write("<br>ScreenLeft: " + myWindow.screenLeft);
myWindow.document.write("<br>ScreenTop: " + myWindow.screenTop + "</p>");
}
</script>
</head>
<body>
<input type="button" value="打開 '我的窗口'" onclick="openWin()">
</body>
</html>
嘗試一下 ?
Window 對象
更多建議: