Chrome和Firefox的window.close()方法的替代方法 [英] Alternative to window.close() method for Chrome and Firefox

查看:400
本文介绍了Chrome和Firefox的window.close()方法的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击同一页面上的关闭按钮时,我想关闭我的窗口/标签.

I want to close my window/tab when the close button is clicked on the same page.

我使用了window.close()方法.它适用于IE版本,但不适用于Firefox和Chrome.

I used window.close() method. It works perfectly for IE versions, but it doesn't work for Firefox and Chrome.

我进行了很多搜索以寻求解决方案.请给我一个演示解决方案.

I searched a lot for a solution. Please give me a demo solution.

推荐答案

根据 MDN

仅允许使用window.open()方法由脚本打开的窗口调用

[Window.close()].如果未通过脚本打开窗口,则JavaScript控制台中会出现以下错误:脚本可能无法关闭不是由脚本打开的窗口.

[Window.close()] is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

因此,要使用此方法,必须使用window.open()方法才能通过window.close()将其关闭.

So in order to use this method, you have to use the window.open() method to be able to close it via window.close().

这篇关于Chrome和Firefox的window.close()方法的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆