Chrome和Firefox的window.close()方法的替代方法

Chrome和Firefox的window.close()方法的替代方法

[英] Alternative to window.close() method for Chrome and Firefox

问题描述

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

我使用了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.open()方法才能通过window.close()将其关闭.

posted on 2022-04-24 17:39  癫狂编程  阅读(252)  评论(0编辑  收藏  举报

导航

好的代码像粥一样,都是用时间熬出来的