Window.open大全

1、最基本的弹出窗口代码

 

<SCRIPT LANGUAGE="javascript"> 
  <!-- 

  window.open ('page.html')  //打开一个窗口

  --> 
</SCRIPT> 

 

        javascripts代码应该放在两个<SCRIPT>...<>SCRIPT>之间,<!-- -->是为了解决一些低版本浏览器的兼容性。

 

        运行结果:打开一个窗口

 

2、带参数的弹出窗口

 

<SCRIPT LANGUAGE="javascript"> 
  <!-- 

       window.open ('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no')

  --> 
</SCRIPT> 

 

  window.open 弹出新窗口的命令;
  page.html'弹出窗口的文件名;
  newwindow 弹出窗口的名字(不是文件名),非必须,可用空''代替;
  height=100 窗口高度;
  width=400 窗口宽度;
  top=0 窗口距离屏幕上方的象素值;
  left=0 窗口距离屏幕左侧的象素值;
  toolbar=no 是否显示工具栏,yes为显示;
  menubar,scrollbars 表示菜单栏和滚动栏。
  resizable=no 是否允许改变窗口大小,yes为允许;
  location=no 是否显示地址栏,yes为允许;
  status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;

 

3、最大化弹出窗口

 

<html>
<head>
    <title>window.open最大化 </title>
</head>
<body>

    <script language="javascript">
  <!-- 
      function openTest()
        {
            var ww = window.screen.availwidth - 10;    //可用宽度减去10
            var hh = window.screen.availheight - 60;   //可用高度减去60
            window.open("test.htm", "", "toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=yes,top=0,left=0,width=" + ww + ",height=" + hh);

        }
  -->
    </script>

    <input id="Button" type="button" value="最大化新窗口" οnclick="openTest()" />
</body>
</html>

 

4、弹出窗口并居中

 

<html>
<head>
    <title>window.open居中 </title>
</head>
<body>

    <script language="javascript">
  <!-- 
          function openTest(url, name, iWidth, iHeight)
        {
            var url;
            //转向网页的地址;

            var name;
            //网页名称,可为空;

            var iWidth;
            //弹出窗口的宽度;

            var iHeight;
            //弹出窗口的高度;

            var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
            //获得窗口的垂直位置;

            var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
            //获得窗口的水平位置;
            
            window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
        }
  -->
    </script>

    <input id="Button" type="button" value="居中新窗口" οnclick="openTest('test.htm','居中新窗口',400,400)" />
</body>
</html>

 

5、弹出子窗口并返回值

 

<html>
<head>
    <title>window.open返回值父窗口</title>
    <style type="text/css">
        #father
        {
            width: 500px;
            height: 100px;
        }
    </style>

    <script type="text/javascript">
        function openTest()
        {
            window.open('test.htm')
        }
    </script>

</head>
<body>
    <input id="father" type="text" /><br />
    <br />
    <input id="Button" type="button" value="打开子窗口" οnclick="openTest()" /><br />
</body>
</html>

 

<html>
<head>
    <title>window.open返回值子窗口</title>
    <style type="text/css">
        #Text1
        {
            height: 100px;
            width: 500px;
        }
    </style>
    <script type="text/javascript">
        function openerTest()
        {
            window.opener.document.getElementById("father").value = Text1.value;
            window.close()
    }
    </script>
</head>
<body>

    <p>
        <input id="Text1" type="text" /><br />
        <br />
        <input id="Button" type="button" value="关闭并返回值" οnclick="openerTest()" /></p>

</body>
</html>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值