请问js如何关闭当前页面,能够兼容主流的浏览器,网上找的这个例子,没有用
//FF中需要修改配置window.close方法才能有作用,为了不需要用户去手动修改,所以用一个空白页面显示并且让后退按钮失效
//Opera浏览器旧版本(小于等于12.16版本)内核是Presto,window.close方法有作用,但页面不是关闭只是跳转到空白页面,后退按钮有效,也需要特殊处理
var userAgent = navigator.userAgent;
if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Presto") != -1) {
window.location.replace("about:blank");
} else {
window.opener = null;
window.open("", "_self");
window.close();
}
Chrome下提示:
Scripts may close only the windows that were opened by it.
<a href="javascript:window.opener=null;window.open('','_self');window.close();">关闭</a>