如何在屏幕中央打开一个特定的窗口
在学习中,无意看到了如下代码,觉得很不错,收藏了。
source:How do I open a new window of a certain size?
1: <html>
2: <head>
3: <script>
4: <!--5: function wopen(url, name, w, h)
6: {7: // Fudge factors for window decoration space.
8: // In my tests these work well on all platforms & browsers.
9: w += 32; 10: h += 96; 11: wleft = (screen.width - w) / 2; 12: wtop = (screen.height - h) / 2;13: // IE5 and other old browsers might allow a window that is
14: // partially offscreen or wider than the screen. Fix that.
15: // (Newer browsers fix this for us, but let's be thorough.)
16: if (wleft < 0) {
17: w = screen.width; 18: wleft = 0; 19: }20: if (wtop < 0) {
21: h = screen.height; 22: wtop = 0; 23: }24: var win = window.open(url,
25: name,26: 'width=' + w + ', height=' + h + ', ' +
27: 'left=' + wleft + ', top=' + wtop + ', ' +
28: 'location=no, menubar=no, ' +
29: 'status=no, toolbar=no, scrollbars=no, resizable=no');
30: // Just in case width and height are ignored
31: win.resizeTo(w, h);32: // Just in case left and top are ignored
33: win.moveTo(wleft, wtop); 34: win.focus(); 35: }36: // -->
37: </script>
38: </head>
39: <body>
40: <a href="page.html" target="popup"
41: onClick="wopen('page.html', 'popup', 300, 200); return false;">
42: Click here to open the page in a new window. </a>
43: </body>
44: </html>
浙公网安备 33010602011771号