更多例子
打开一个具有指定左侧和顶部位置的新窗口,并返回其坐标:
var myWindow = window.open("", "myWin", "left=700, top=350, width=200, height=100");
myWindow.document.write("<p>This is 'myWin'");
myWindow.document.write("<br>ScreenX: " + myWindow.screenX);
myWindow.document.write("<br>ScreenY: " + myWindow.screenY + "</p>");
尝试一下
跨浏览器解决方案(使用screenLeft和screenTop for IE8及更早版本):
// 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>");
尝试一下