方式一:JS代码创建窗口
js 代码
- <script>
- var popup = new Object()
- function CenterPopup(URL, width, height)
- {
- // Window dimensions:
- var theWidth, theHeight;
- if (window.innerWidth)
- theWidth=window.innerWidth;
- else if (document.documentElement && document.documentElement.clientWidth)
- theWidth=document.documentElement.clientWidth;
- else if (document.body)
- theWidth=document.body.clientWidth;
- if (window.innerHeight)
- theHeight=window.innerHeight;
- else if (document.documentElement && document.documentElement.clientHeight)
- theHeight=document.documentElement.clientHeight;
- else if (document.body)
- theHeight=document.body.clientHeight;
- // Window origin
- var originX, originY;
- if (window.innerHeight) {
- originX=screenX+(window.outerWidth-window.innerWidth);
- originY=screenY+(window.outerHeight-window.innerHeight);
- }
- else {
- originX=screenLeft;
- originY=screenTop;
- }
- var X = theWidth/2;
- var Y = theHeight/2;
- var features='"scrollbars=0, ' +
- 'width=' + width + ', ' +
- 'height=' + height + ', ' +
- 'top=' + parseInt(originY + (Y - (height/2))) + ', ' + //
- 'left=' + parseInt(originX + (X - (width/2))) + '"';
- popup = window.open(URL, "PopUp", features);
- popup.focus()
- }
- </script>
- <html>
- <body>
- <a href="#" οnclick="CenterPopup('house.html',500,400)">open new window</a>
- </body>
- </html>
方式二:open()打开窗口
js 代码
- <HTML>
- <Head>
- <Script Language=JavaScript>
- var popWin = "";
- function openwin(url, strWidth, strHeight){
- if (popWin != ""){popWin.close()}
- leftStr = (screen.width-strWidth)/2;
- topStr = (screen.height-strHeight)/2;
- windowProperties = "toolbar=no,menubar=no,scrollbars=no,stausbar=no,height="+strHeight+",width="+strWidth+",left="+leftStr+",top="+topStr+"";
- popWin = window.open(url,'newWin',windowProperties);
- }
- </Script>
- </Head>
- <Body>
- <a href="#" onClick="openwin('house.html',400,325)">Open a centered popup window</a>
- </Body>
- </HTML>