玩转 Javascript 弹出窗口, 居中与居角扩大窗口至屏幕最大值 By shawl.qiu说明:主要使用 Js 的 setInterval() 和 clearInterval() 函数完成操作.目录: 1 . 居中弹出窗口, 并逐步扩大 2 . 居角弹出窗口, 并逐步扩大 3 . 附加: 双击滚屏, 单击停止, 以 Scroll bar 的相对位置滚屏shawl.qiu 2006 - 10 - 24 http: // blog.csdn.net/btbtd 1 . 居中弹出窗口, 并逐步扩大linenum < script type = " text/javascript " > // <![CDATA[ if (navigator.appName == " Microsoft Internet Explorer " ) ... { //最大化窗口 self.moveTo(-5,-5) self.resizeTo(screen.availWidth +8,screen.availHeight+8) //这个脚本定义的宽度其实比原窗口还要大那么一点. } var w = h = 200 ; x = (screen.width - w) / 2 ; y = (screen.height - h) / 2 ; var n = open( '' , ' newWin ' , ' width= ' + w + ' ,height= ' + h + ' ,left= ' + x + ' ,right= ' + x + ' ,top= ' + y + ' ,bottom= ' + y); n.document.write( ' <script> document.write("temp"); /* 临时内容, 去掉出错 */ document.body.innerHTML=""; /* 清空页面内容 */ document.οnclick=function(){ close();} /* 单击关闭窗口 */ </script> ' ); n.document.write( ' <h2>test moving window</h2> ' ); n.focus(); var timer = setInterval( ' fMovingWin() ' , 1 ); function fMovingWin() ... { if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) ...{ clearInterval(timer); return; } try...{ if(w<=screen.width+8)w+=2; if(h<=screen.height+8)h+=2; n.resizeTo(w, h) x=(screen.width-w)/2; y=(screen.height-h)/2; n.moveTo(x,y) } catch(e) ...{} //shawl.qiu script } // ]]> </ script > 2 . 居角弹出窗口, 并逐步扩大linenum < script type = " text/javascript " > // <![CDATA[ if (navigator.appName == " Microsoft Internet Explorer " ) ... { //最大化窗口 self.moveTo(-5,-5) self.resizeTo(screen.availWidth +8,screen.availHeight+8) //这个脚本定义的宽度其实比原窗口还要大那么一点. } var w = h = 200 ; x = y =- 5 ; var n = open( '' , ' newWin ' , ' width= ' + w + ' ,height= ' + h + ' ,left= ' + x + ' ,right= ' + x + ' ,top= ' + y + ' ,bottom= ' + y); n.document.write( ' <script> document.write("temp"); /* 临时内容, 去掉出错 */ document.body.innerHTML=""; /* 清空页面内容 */ document.οnclick=function(){ close();} /* 单击关闭窗口 */ </script> ' ); n.document.write( ' <h2>test moving window</h2> ' ); n.focus(); var timer = setInterval( ' fMovingWin() ' , 1 ); function fMovingWin() ... { if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) ...{ clearInterval(timer); return; } try...{ if(w<=screen.width+8)w+=2; if(h<=screen.height+8)h+=2; n.resizeTo(w, h) //从右下角逐步扩大窗口 /**//* x=screen.width-w y=screen.height-h n.moveTo(x,y) */ //从左上角逐步扩大窗口 n.moveTo(x,y) } catch(e) ...{} //shawl.qiu script } // ]]> </ script > 3 . 附加: 双击滚屏, 单击停止, 以 Scroll bar 的相对位置滚屏linenum < script type = " text/javascript " > // <![CDATA[ function scb() ... { timer=setInterval('scrollBy(0,1)',1000) } document.onmousedown = function () ... { try...{ clearInterval(timer);} catch(e)...{} } document.ondblclick = function () ... { scb(); } // ]]> //shawl.qiu script </ script >