关于关闭弹出窗口

时间:2021-12-26 23:41:27

新弹出才能关闭

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();
}
}
}

火狐和谷歌 需要弹出新窗口才能关闭

http://blog.csdn.net/aerchi/article/details/41441429

function closeWindows() {
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
//alert(browserName + " : "+browserVer);

//document.getElementById("flashContent").innerHTML = "<br>&nbsp;<font face='Arial' color='blue' size='2'><b> You have been logged out of the Game. Please Close Your Browser Window.</b></font>";

if(browserName == "Microsoft Internet Explorer"){
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
if (ie7)
{
//This method is required to close a window without any prompt for IE7 & greater versions.
window.open('','_parent','');
window.close();
}
else
{
//This method is required to close a window without any prompt for IE6
this.focus();
self.opener
= this;
self.close();
}
}
else{
//For NON-IE Browsers except Firefox which doesnt support Auto Close
try{
this.focus();
self.opener
= this;
self.close();
}
catch(e){

}

try{
window.open(
'','_self','');
window.close();
}
catch(e){

}
}
}
<script type="text/javascript">
function closeWP() {
var Browser = navigator.appName;
var indexB = Browser.indexOf('Explorer');

if (indexB > 0) {
var indexV = navigator.userAgent.indexOf('MSIE') + 5;
var Version = navigator.userAgent.substring(indexV, indexV + 1);

if (Version >= 7) {
window.open(
'', '_self', '');
window.close();
}
else if (Version == 6) {
window.opener
= null;
window.close();
}
else {
window.opener
= '';
window.close();
}

}
else {
window.close();
}
}
</script>
 $("#closess").click(function(event) {
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();
}

});
}
<!-- saved from url=(0059)https://browserstrangeness.bitbucket.io/window_to_close.htm -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Window Close Method</title>

<script language="javascript">

function quitBox(cmd)
{
if (cmd=='quit')
{
open(location,
'_self').close();
}
return false;
}

</script>

</head>

<body>

<input type="button" value="Close This Window/Tab" onclick="return quitBox('quit');">

<br><br>

Tested and working
in Chrome 34-42, Safari 7-8, Internet Explorer 11 and Firefox 27-40

<br><br>

This window
is not the complete code, but the second part only. This is the page that is opened by the working script.

<br><br>

To make
this work, go to the opener page here: <a href="http://browserstrangeness.bitbucket.org/window_close_tester.htm">http://browserstrangeness.bitbucket.org/window_close_tester.htm</a>



</body></html>