浏览器关闭 window.close无效

参考:https://blog.csdn.net/qq_38990451/article/details/115540392

简单的说就是:window.close()方法只能关闭由window.open()或者浏览器直接输入url打开的页面,其余情况安全考虑是被限制的

解决方案1:

window.location.href = 'about:blank'
window.close()
解决方案2:

window.opener = null
window.open('about:blank', '_top').close()
解决方案3:

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()
}
解决方案4:

查看当前页面之前的一系列打开方式是不是用window.open()打开的,如果不是,换成此方法打开即可

posted @ 2023-01-12 16:36  飞鹰之歌  阅读(517)  评论(0)    收藏  举报