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

来源:互联网 发布:销售数据分析报告 编辑:程序博客网 时间:2024/05/16 02:44

 1. 居中弹出窗口, 并逐步扩大

    linenum
  1. <script type="text/javascript">
  2. //<![CDATA[
  3.     if (navigator.appName=="Microsoft Internet Explorer") {
  4.         //最大化窗口
  5.         self.moveTo(-5,-5)
  6.         self.resizeTo(screen.availWidth +8,screen.availHeight+8)
  7.         //这个脚本定义的宽度其实比原窗口还要大那么一点.
  8.     }
  9.     var w=h=200;
  10.     x=(screen.width-w)/2;
  11.     y=(screen.height-h)/2;
  12.     var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y);
  13.         n.document.write('
  14.         <script>
  15.             document.write("temp"); /* 临时内容, 去掉出错 */ 
  16.             document.body.innerHTML=""; /* 清空页面内容 */ 
  17.             document.onclick=function() /* 单击关闭窗口 */ 
  18.         </script>');
  19.         n.document.write('<h2>test moving window</h2>');
  20.         n.focus();
  21.         
  22.     var timer=setInterval('fMovingWin()',1);
  23.     
  24.     function fMovingWin(){
  25.         if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) {
  26.             clearInterval(timer);
  27.             return;
  28.         }
  29.         try{
  30.             if(w<=screen.width+8)w+=2;
  31.             if(h<=screen.height+8)h+=2;
  32.             n.resizeTo(w, h)
  33.             x=(screen.width-w)/2;
  34.             y=(screen.height-h)/2;
  35.             n.moveTo(x,y)
  36.         } catch(e) {} //shawl.qiu script
  37.     }
  38. //]]>
  39. </script>

2. 居角弹出窗口, 并逐步扩大

    linenum
  1. <script type="text/javascript">
  2. //<![CDATA[
  3.     if (navigator.appName=="Microsoft Internet Explorer") {
  4.         //最大化窗口
  5.         self.moveTo(-5,-5)
  6.         self.resizeTo(screen.availWidth +8,screen.availHeight+8)
  7.         //这个脚本定义的宽度其实比原窗口还要大那么一点.
  8.     }
  9.     var w=h=200;
  10.     x=y=-5;
  11.     var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y);
  12.         n.document.write('
  13.         <script>
  14.             document.write("temp"); /* 临时内容, 去掉出错 */   document.body.innerHTML=""; /* 清空页面内容 */ 
  15.             document.onclick=function() /* 单击关闭窗口 */ 
  16.         </script>');
  17.         n.document.write('<h2>test moving window</h2>');
  18.         n.focus();
  19.         
  20.     var timer=setInterval('fMovingWin()',1);
  21.     
  22.     function fMovingWin(){
  23.         if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) {
  24.             clearInterval(timer);
  25.             return;
  26.         }
  27.         try{
  28.             if(w<=screen.width+8)w+=2;
  29.             if(h<=screen.height+8)h+=2;
  30.             n.resizeTo(w, h)
  31.             
  32.             //从右下角逐步扩大窗口
  33. /*             x=screen.width-w
  34.             y=screen.height-h
  35.             n.moveTo(x,y) */
  36.             
  37.             //从左上角逐步扩大窗口
  38.             n.moveTo(x,y)
  39.         } catch(e) {}  //shawl.qiu script
  40.     }
  41. //]]>
  42. </script>

3. 附加: 双击滚屏, 单击停止, 以 Scroll bar 的相对位置滚屏

    linenum
  1. <script type="text/javascript">
  2. //<![CDATA[
  3.     function scb()
  4.     document.onmousedown=function() catch(e){} }
  5.     document.ondblclick=function()
  6. //]]> //shawl.qiu script
  7. </script>

注意: 拷贝代码后需要 查找 " ", 并替换为 "". (不加引号)
原因: CSDN 的编码器在行末自动添加空格符" ", 而这段代码正好使用 js 的 在行末作为行链接, 因此行末就是空格, 而不是 , 需要手动转正.