JavaScript中window.open()打開與window.close()關閉


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.dhnblog.com/','_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.dhnblog.com/','_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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM