1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面

scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面

时间:2021-03-25 04:07:45

相关推荐

scripts may close only the windows that were opened by it 浏览器JS控制无法关闭当前页面

非window.open形式打开的子页面用js的window.close在chrome下就会提示scripts may close only the windows that were opened by it。

网上的很多解决方法都是把当前页面为空,在IE和360浏览器也不能直接关闭页面,翻到stack overflow的解决方案:

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

open(location, '_self').close(); 加了这个非火狐和chrome(像360浏览器之类)就能直接把当前页面关闭了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。