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>
|