分享

JavaScript中window.open()打开与window.close()关闭

 小世界的野孩子 2021-11-14

close()关闭窗口,语法书写如下,其次使用close()在打开新窗口的同时,关闭该窗口,是看不到被打开窗口的

1 window.close();//关闭本窗口
2 <窗口对象>.close();//关闭指定的窗口

 代码展示:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>JavaScript中window.open()与window.close()</title>
 6     <script type="text/javascript">
 7         function myopen(){
 8             window.open('https://www.baidu.com/','_blank','width=300,height=200,left=0,meunbar=no,toolbar=no,scrollbar=yes,status=no');
 9         }
10         
11         var ceshi=window.open('https://www.cnblogs.com/dhnblog/p/12494648.html')//将新打的窗口对象,存储在变量ceshi中
12         // // ceshi.wondows.close()   错误写法
13         ceshi.close()
14     </script>
15 </head>
16 <body>
17     <input type="button" name="" id="" value="点击打开新窗口" onclick="myopen()" />
18 </body>
19 </html>

 使用<窗口对象>.close();//关闭指定的窗口 代码展示:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>通过变量关闭窗口</title>
 6     <script type="text/javascript">
 7         function myopen(){
 8             var ceshi=window.open('https://www.baidu.com/','_blank','width=300,height=200,left=0,meunbar=no,toolbar=no,scrollbar=yes,status=no');
 9             ceshi.close()
10         }
11     </script>
12 </head>
13 <body>
14     <input type="button" name="" id="" value="我不信你可以打开" onclick="myopen()" />
15 </body>
16 </html>

 至于window.close();//关闭本窗口 暂时不是很懂,感兴趣的可以参考下这个,后期有机会在完善

  1. Javascript:window.close()不起作用?

  2. window.close()的用法 
  3. window方法:close()

==修改时间2020/04/08/20:58 window.close();//关闭本窗口

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>JavaScript-关闭窗口(window.close)</title>
 6         <script type="text/javascript">
 7             // window.close();   //关闭本窗口
 8             // <窗口对象>.close();   //关闭指定的窗口
 9             
10             // window.open('http://www./','_blank','top=100,left=100,width=200,height=300,menubar=yes,toolbar=yes,status=no,scrollbars=yes');
11             //window.close();
12                 
13             var mywin=window.open('http://www./','_blank','top=100,left=100,width=200,height=300,menubar=yes,toolbar=yes,status=no,scrollbars=yes');
14             // //将新打的窗口对象,存储在变量mywin中
15             mywin.close();
16         </script>
17     </head>
18     <body>
19         <p>上面代码在打开新窗口的同时,关闭该窗口,看不到被打开的窗口。</p>
20     </body>
21 </html>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多