1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Scripts may close only the windows that were opened by them.脚本只能关闭它们打开的窗口。

Scripts may close only the windows that were opened by them.脚本只能关闭它们打开的窗口。

时间:2019-07-20 07:47:52

相关推荐

Scripts may close only the windows that were opened by them.脚本只能关闭它们打开的窗口。

当分享链接访问页面,使用window.close()关闭当面页面会报错。

window.close()

Scripts may close only the windows that were opened by them.

有些浏览器可能会阻止通过脚本来关闭窗口,尤其是在不是通过脚本打开的窗口(如用户手动输入或通过链接打开的窗口)。这是为了避免恶意脚本滥用这个功能。因此,这段代码可能不适用于所有浏览器和情况。

使用这段代码代替window.close(),就能关闭当前页面。

//关闭页面const closePage = () => {if (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('Chrome') != -1) {window.location.href = 'about:blank'window.close()} else {window.opener = nullwindow.open('', '_self')window.close()}}

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