http://www.tek-tips.com/faqs.cfm?fid=2296解释了如何做到这一点。但由于弹出窗口拦截器,我建议使用浮动 Div。
假设您要打开一个大小为 200h x 150w 的窗口。通过取一半的高度和宽度(分别为 100 和 75),您可以确定窗口的中心。然后通过一些数学运算,您可以将窗口居中。这是如何完成的
<SCRIPT LANGUAGE="JavaScript">
function MyPopUpWin() {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
var win2 = window.open("filename.htm","Window2","status=no,height=200,width=150,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
win2.focus();
}
</SCRIPT>
要在 HTML 中调用此函数,请使用:
<A HREF="javascript:MyPopUpWin()">This is the link</a>