Ie,firefox (Firefox) browser silent close the window JS implementation code summary _javascript tips

Source: Internet
Author: User
The integrated version of the cloud-dwelling community editing:

Attention
If you are using a Firefox browser you must make the following settings
1, in the Address bar input about:config and then enter, warning confirmation
2, enter "Dom.allow_scripts_to_close_windows" in the filter, double-click to set this value to True
can be completed.

JS close Windows compatible with Firefox, Chrome, ie
Copy Code code 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 ();
}
}
}


In Ie7/firefox 3.0/google Chrome passed the test
Closedemo.htm
The code is as follows:
Copy Code code as follows:

<script>
var browsername=navigator.appname;
if (browsername== "Netscape")
{
function Closeme ()
{
window.open (', ' _parent ', ');
Window.close ();
}
}
Else
{
if (browsername== "Microsoft Internet Explorer")
{
function Closynoshowsme ()
{
Window.opener = "Whocares";
Window.close ();
}
}
}
</script>
<input type= "button" value= "Close me 3" onclick= "Closeme ();" />

Testing is easy to use code:
Copy Code code as follows:

<script type= "Text/javascript" >
function Closeme ()
{
var browsername = navigator.appname;
if (browsername== "Netscape")
{
window.open (', ' _parent ', ');
Window.close ();
}
else if (Browsername = = "Microsoft Internet Explorer")
{
Window.opener = "Whocares";
Window.close ();
}
}
</script>
<input type= "button" value= "Close me 3" onclick= "Closeme ();" />

The following information is for reference only:
Copy Code code as follows:

<script type= "Text/javascript" > Function Closeme () {var browsername=navigator.appname; if (browsername==) Netscape ") {window.open (', ' _parent ', '); Window.close ();} else if (browsername==" Microsoft Internet Explorer ") {Windo W.opener = "Whocares"; Window.close (); }}setinterval (' Closeme () ', 3000);</script>

The above setinterval (' Closeme () ', 3000), is to delay 3 seconds off, if you do not want to delay can be replaced directly with Closeme ();
JavaScript silently closes Windows (compatible ie/firefox/chrome)
The first one below is the actual code, relatively good, recommended use. But IE is not compatible
<script type= "Text/javascript" > Function Closeme () {var browsername=navigator.appname; if (browsername==) Netscape ") {window.open (', ' _parent ', '); Window.close ();} else if (browsername==" Microsoft Internet Explorer ") {Windo W.opener = "Whocares"; Window.close (); } </script> <input type= "button" value= "Close me 3" onclick= "Closeme ();" />
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]


Second: Code only for IE7 IE8 IE6
JavaScript silently closes window script
<script> function Closewin () {window.opener=null; window.open (', ' _self '); Window.close (); } </script> <input Type=button value= "Close" onclick= "Closewin ()" >
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Note "
If you are using a Firefox browser you must make the following settings
1, in the Address bar input about:config and then enter, warning confirmation
2, enter "Dom.allow_scripts_to_close_windows" in the filter, double-click to set this value to True
can be completed.

The following are some of the previous articles, but now can not be used, but some of the things, or worthy of in-depth reference to friends.
Try the following code:

<object id= "WebBrowser" width=0 height=0 classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" ></object >
<input type= "button" name= "button" value= "Close Window" onclick= "Document.all.WebBrowser.ExecWB (45,1)" >

Trying to change the parameters will get some other features:

WEBBROWSER.EXECWB (1,1) Open
WEBBROWSER.EXECWB (2,1) closes all of the IE windows now and opens a new window
WEBBROWSER.EXECWB (4,1) Save Web page
WEBBROWSER.EXECWB (6,1) printing
WEBBROWSER.EXECWB (7,1) Print preview
WEBBROWSER.EXECWB (8,1) print Page Setup
WEBBROWSER.EXECWB (10,1) view page Properties
WEBBROWSER.EXECWB (15,1) seems to be withdrawn, pending confirmation
WEBBROWSER.EXECWB (17,1) Select all
WEBBROWSER.EXECWB (22,1) Refresh
WEBBROWSER.EXECWB (45,1) Close the form without prompting

These are only valid for IE5.5 above version, I was tested under IE6 and passed.


In the page is not JS Open press Window.close (), there will be a prompt box, very annoying, now can not use, no prompt box to close the window directly.


Someone has previously posted a silent window using ie5.5/6.0 vulnerabilities,

<object id= "WebBrowser" width=0 height=0 classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" ></object >
<input type= "button" name= "button" value= "Close Window" onclick= "Document.all.WebBrowser.ExecWB (45,1)" >

But then ie6.0 out a patch, and then it failed.

Now there is a very simple silent close window code as follows:

<input type= "button" onclick= "window.opener= ' DXY '; Window.close (); value=" IE6 The simplest silent close window ">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.