JS closes the current page code (compatible with all browsers

Source: Internet
Author: User

1. Close the window without any hint JS code

Window.close () is OK, but it will give you a hint. The page you are viewing is attempting to close the window. Do you want to close the window? "How can you not eject this hint?"
"If you open this page for the first time, Window.close () will pop-up prompts, if this page is from other pages window.open () out of the page, Window.close (), it will not appear

The code is as follows Copy Code

<a href= "Javascript:window.opener=null;window.open (', ' _self '); Window.close ();" > Close </a>

2. Custom Prompt shutdown

The code is as follows Copy Code

<script language= "JavaScript" >
function Custom_close () {
if (confirm) (Are you sure you want to close this page?) ")){
Window.opener=null;
window.open (', ' _self ');
Window.close ();
}
else{}
}
</script>

This script is a generic script for IE6 and IE7.

The code is as follows Copy Code

<input id= "btnclose" type= "button" value= "close this page" onclick= "Custom_close ()"/>

3. Close the current page: <a href= "Javascript:window.opener=null;window.close ();" > Close </a>, if the button is:

The code is as follows Copy Code

Response.Write ("<script language=" JavaScript ">window.opener=null;window.close ();</script>");


Closes the current page and opens a new page (not prompted)

The code is as follows Copy Code

function Closewinandopen (URL) {

var swinname = "LR" +parseint (Math.random () * 100000000);//using random number to deal with Winname

window.open (Url,swinname, ' toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable= Yes,copyhistory=yes ');

Closewin ();

}

Close the current page

The code is as follows Copy Code

function Closewin () {

Window.opener=null;

window.open (', ' _self ');

Window.close ();

}

Compatible with all browsers close Web page method

The code is as follows Copy Code

<script type= "Text/javascript" >
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 '; Firefox default state is not window.open page window.close is invalid
Window.history.go (-2);
}
else {
Window.opener = null;
window.open (', ' _self ', ');
Window.close ();
}
}
</script>

To determine the browser JS code:

The code is as follows Copy Code

<script language= "JavaScript" >
<!--
function Getos ()
{
var osobject = "";
if (Navigator.userAgent.indexOf ("MSIE") >0) {
return "MSIE";
}
if (Isfirefox=navigator.useragent.indexof ("Firefox") >0) {
return "Firefox";
}
if (Issafari=navigator.useragent.indexof ("Safari") >0) {
return "Safari";
}
if (Iscamino=navigator.useragent.indexof ("Camino") >0) {
return "Camino";
}
if (Ismozilla=navigator.useragent.indexof ("gecko/") >0) {
return "Gecko";
}

}
Alert ("Your browser type is:" +getos ());
-->
</script>

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.