window.close 兼容性

window.close 在被 window.open 的页面上使用的时候没有问题

当在浏览器敲击地址的页面上需要使用如下标准代码:

var userAgent = navigator.userAgent;
if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
   window.location.href="about:blank";
} else {
   window.opener = null;
   window.open("", "_self");
   window.close();
}});

其中:
1. firefox 和 chrome 直接不会执行close 函数,会报错(Scripts may close only the windows that were opened by it.)
2. ie 全系列浏览器(包括Edge)会弹出Alert 提示

备注:
在localhost域名下,不会出现 ie的弹窗和chrome报错情况,会>正常执行关闭自己

你可能感兴趣的:(javasc)