The script Window.close() is used to close the current window. If Window.close() is executed in the window of window.open, the window will be closed smoothly, but if it is executed in a non-window Execute Window.close() in the window opened by .open, a prompt window will pop up, as follows:
It is also very simple to eliminate this prompt box in the program, but it is slightly different in IE6 and IE7
1. IE6
<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>IE6Close</title> <script type="text/javascript"> function closeWin() { window.opener=null; window.close(); } </script> </head> <body> <form id="form2" runat="server"> <div> <input id="btnClose" type="button" value="close" onclick="closeWin()"/> </div> </form> </body> </html>
2.IE7
<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>IE7Colse</title> <script type="text/javascript"> function closeWin() { window.open('','_self',''); window.close(); } </script> </head> <body> <form id="form2" runat="server"> <div> <input id="btnClose" type="button" value="close" onclick="closeWin()"/> </div> </form> </body> </html>
The above is the entire content of this article, I hope you all like it.