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();//關閉本視窗 暫時不是很懂,感興趣的可以參考下這個,后期有機會在完善
-
Javascript:window.close()不起作用?
- window.close()的用法
- 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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/141690.html
標籤:JavaScript
