In js, the window or page cannot be judged. close () function, but if you want to be compatible with all browsers to close the current window, you do not directly use window. close.
Windows built-in Methods
Window. close ()
The Code is as follows: |
Copy code |
<A href = "javascript: self. close ()"> close the window </a> |
There are many problems with this method, so we will not discuss it much if it is incompatible. Let's look at another instance.
Window. close (), but it will prompt "the webpage you are viewing is trying to close the window. Close the window ?", How can I not bring up this prompt?
"If you open this webpage for the first time, window. close () will pop up a prompt, if this page is from another web page window. open () page, window. close (), no prompt will appear
The window does not display the js Code that is automatically closed.
The Code is as follows: |
Copy code |
// The error message "close" appears in the normal mode. Function closeie (){ Window. close (); } // Disable IE6. No prompt Function closeie6 (){ Window. opener = null; Window. close (); } // Disable IE7. No prompt Function closeie7 (){ Window. open ('', '_ top '); Window. top. close (); }
However |
Ff cannot be used anymore. Later, I found a function that is compatible with all browsers to close the current page.
The Code is as follows: |
Copy code |
Function CloseWebPage (){ If (navigator. userAgent. indexOf ("MSIE")> 0 ){ If (navigator. userAgent. indexOf ("MSIE 6.0")> 0 ){ Window. opener = null; Window. close (); } Else { Window. open ('', '_ top '); Window. top. close (); } } Else if (navigator. userAgent. indexOf ("Firefox")> 0 ){ Window. location. href = 'about: blank '; } Else { Window. opener = null; Window. open ('', '_ self ',''); Window. close (); } } |