window.close 兼容性

来源:互联网 发布:淘宝哪里可以定做鞋子 编辑:程序博客网 时间:2024/05/19 03:47

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报错情况,会>正常执行关闭自己

0 0
原创粉丝点击