Home >Web Front-end >JS Tutorial >IE, firefox (Firefox) browser silently closes the window js implementation code summary_javascript skills

IE, firefox (Firefox) browser silently closes the window js implementation code summary_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:46:051805browse

Version edited and integrated by Script House:

Note
If you are using the firefox browser, you must make the following settings
1. Enter about:config in the address bar Then press Enter and confirm the warning
2. Enter "dom.allow_scripts_to_close_windows" in the filter, double-click to set this value to true
and you are done.

js closing window is compatible with firefox, chrome, and ie

Copy code The code is as follows:

function windowclose() {
var browserName = navigator.appName;
if (browserName=="Netscape") {
window.open('', '_self', '');
window.close();
}
else {
if (browserName == "Microsoft Internet Explorer"){
window.opener = "whocares";
window.opener = null;
window.open('', '_top');
window.close();
}
}
}


Passed the test in IE7/ Firefox 3.0/ Google Chrome
CloseDemo.htm
The code is as follows:
Copy the code The code is as follows :

<script> <br>var browserName=navigator.appName; <br>if (browserName=="Netscape") <br>{ <br>function closeme() <br> { <br>window.open('','_parent',''); <br>window.close(); <br>} <br>} <br>else <br>{ <br>if (browserName == "Microsoft Internet Explorer") <br>{ <br>function closynoshowsme() <br>{ <br>window.opener = "whocares"; <br>window.close(); <br>} <br> } <br>} <br></script>


Code that is easier to use for testing:
Copy code The code is as follows:




The following content is for reference only:
Copy code The code is as follows:



The above setInterval('closeme()',3000); is to delay closing for 3 seconds. If you don't want to delay, you can directly replace it with closeme (); that’s it.
JavaScript silently closes the window (compatible with IE/Firefox/Chrome)
The first one below is the actual code, which is pretty good and recommended. But ie compatibility is not good

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

Second: Code only for ie7 ie8 ie6
javascript silent window closing script

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute ]<script> function CloseWin(){ window.opener=null; window.open('','_self'); window.close(); } </script>
Note "
If you are using the firefox browser, you must make the following settings
1. Enter about:config in the address bar and press Enter to confirm the warning
2. Enter "dom.allow_scripts_to_close_windows" in the filter and double-click to set this value to true
That's it But some of the things are still worthy of reference by friends who want to go deeper.
Try the following code:




Try changing the parameters and you will get some other functions:

WebBrowser.ExecWB(1,1) Open
WebBrowser.ExecWB(2,1) Close all now IE window and open a new window
WebBrowser.ExecWB(4,1) Save web page
WebBrowser.ExecWB(6,1) Print
WebBrowser.ExecWB(7,1) Print preview
WebBrowser .ExecWB(8,1) Print page settings
WebBrowser.ExecWB(10,1) View page properties
WebBrowser.ExecWB(15,1) It seems to be revoked and needs to be confirmed
WebBrowser.ExecWB(17, 1) Select all
WebBrowser.ExecWB(22,1) Refresh
WebBrowser.ExecWB(45,1) Close the form silently

These are only valid for IE5.5 or above. I am It was tested under IE6 and passed.


When you press window.close() on a page that is not opened with js, there will be a prompt box, which is very annoying. You can no longer use it. You can close it directly without the prompt box. Window.


Someone has posted a silent window using IE5.5/6.0 vulnerability,




But then IE6.0 came out with a patch and it became invalid

Now there is a very simple code to close the window silently as follows:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn