• 本站域名:OceanCoder.cn 若您喜欢本站,请添加至收藏夹!
  • 网站少部分资源来源自网络,如有侵犯您的权益,请联系站长删除!
  • 本站所有文章,除特殊标明外,皆为本人原创,转载请注明出处,谢谢合作!
  • 本站所下载的资源,若无特殊说明,使用统一解压密码:oceancoder.cn
  • 本站已实现布局自适应,支持手机端、pad端访问,欢迎体验
  • 本站部分资源可通过微信公众号留言获取,欢迎体验

Scripts may close only the windows that were opened by it

HTML+CSS+JS OceanCoder 2019-02-25 7845 次浏览 0个评论
window.opener=null;
window.open('','_self');
window.close();

使用上述js代码关闭Chrome窗口时弹出错误信息:Scripts may close only the windows that were opened by it


解决方法:

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



已有 7845 位网友参与,快来吐槽:

发表评论