close() closes the window, the grammar is written as follows, and then close() closes the window while opening a new one, so you can't see the open window
1 window.close(); //Close this window 2 <Window Object>.close();//Close the specified window
Code Display:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>JavaScript in window.open()and 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')//Store the newly typed window object in a variable ceshi in 12 // // ceshi.wondows.close() Wrong Writing 13 ceshi.close() 14 </script> 15 </head> 16 <body> 17 <input type="button" name="" id="" value="Click to open a new window" onclick="myopen()" /> 18 </body> 19 </html>
Use <window object>.close();//close the specified window code display:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Close windows by variables</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="I don't believe you can open it" onclick="myopen()" /> 15 </body> 16 </html>
As for window.close(); //Close this window is not very clear for the moment, you can refer to this if you are interested and have the opportunity to improve it later