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>
護理表現出一定的代碼?這將有助於獲得良好的答案。 – 2010-02-13 03:18:12
其實,他確實顯示了一些代碼...只是堆棧溢出剝離出來。這是他的原始帖子,沒有它剝離:http://stackoverflow.com/revisions/c84eca9f-6fc3-4fcf-a3b7-ae690d34d38a/view-source – icktoofay 2010-02-13 04:13:42