baiseda 发表于 2013-1-22 22:29:37

Js弹出窗口、居中、居角、扩大窗口至屏幕最大的代码

1.居中弹出窗口,并逐步扩大
linenum
[*]<scripttype="text/javascript">
[*]//<![CDATA[
[*]if(navigator.appName=="MicrosoftInternetExplorer"){
[*]//最大化窗口
[*]self.moveTo(-5,-5)
[*]self.resizeTo(screen.availWidth+8,screen.availHeight+8)
[*]//这个脚本定义的宽度其实比原窗口还要大那么一点.
[*]}
[*]
[*]varw=h=200;
[*]x=(screen.width-w)/2;
[*]y=(screen.height-h)/2;
[*]varn=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.onclick=function()/*单击关闭窗口*/
[*]</script>');
[*]n.document.write('<h2>testmovingwindow</h2>');
[*]n.focus();
[*]
[*]vartimer=setInterval('fMovingWin()',1);
[*]
[*]functionfMovingWin(){
[*]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.qiuscript
[*]}
[*]
[*]//]]>
[*]</script>
2.居角弹出窗口,并逐步扩大
linenum
[*]<scripttype="text/javascript">
[*]//<![CDATA[
[*]if(navigator.appName=="MicrosoftInternetExplorer"){
[*]//最大化窗口
[*]self.moveTo(-5,-5)
[*]self.resizeTo(screen.availWidth+8,screen.availHeight+8)
[*]//这个脚本定义的宽度其实比原窗口还要大那么一点.
[*]}
[*]
[*]varw=h=200;
[*]x=y=-5;
[*]varn=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.onclick=function()/*单击关闭窗口*/
[*]</script>');
[*]n.document.write('<h2>testmovingwindow</h2>');
[*]n.focus();
[*]
[*]vartimer=setInterval('fMovingWin()',1);
[*]
[*]functionfMovingWin(){
[*]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.qiuscript
[*]}
[*]
[*]//]]>
[*]</script>
3.附加:双击滚屏,单击停止,以Scrollbar的相对位置滚屏
linenum
[*]<scripttype="text/javascript">
[*]//<![CDATA[
[*]functionscb()
[*]document.onmousedown=function()catch(e){}}
[*]document.ondblclick=function()
[*]//]]>//shawl.qiuscript
[*]</script>
注意: 拷贝代码后需要 查找 " ", 并替换为 "". (不加引号)
原因: CSDN 的编码器在行末自动添加空格符" ", 而这段代码正好使用 js 的 在行末作为行链接, 因此行末就是空格, 而不是 , 需要手动转正.
页: [1]
查看完整版本: Js弹出窗口、居中、居角、扩大窗口至屏幕最大的代码