简体   繁体   English

如何关闭最新版本的Mozilla Firefox的窗口?

[英]How to close the window on the latest version of Mozilla Firefox?

I am currently using Mozilla Firefox 30.0 and it seems that it doesn't support window.close() anymore. 我目前正在使用Mozilla Firefox 30.0,似乎它不再支持window.close()

You may refer on the image below or if it is too small for you, here is the link . 你可以参考下面的图片,或者如果它是你太小了,这里是链接

这是我的例子

I opened the website of Google using window.open and then I tried to close it using window.close() but it says undefined . 我使用window.open打开了Google的网站,然后尝试使用window.close()关闭它,但显示为undefined

Is there any other option that I can using to close the window using javascript on firefox? 在firefox上使用javascript是否可以使用其他任何选项来关闭窗口?

The Firebug console unfortunately does not display the warning that goes along with it, which reads (in the regular Firefox Web Console}: 不幸的是,Firebug控制台没有显示警告,而是显示(在常规Firefox Web控制台中):

Scripts may not close windows that were not opened by script. 脚本可能无法关闭脚本未打开的窗口。

Also MDN window.close states: 同样, MDN window.close状态:

This method is only allowed to be called for windows that were opened by a script using the window.open method. 仅允许使用window.open方法由脚本打开的窗口调用此方法。

So, you aren't allowed to call window.close() on windows that were explicitly opened by the user. 因此,不允许在用户明确打开的窗口上调用window.close()

PS: This isn't new behavior, but around for ages (even before Firefox was called Firefox). PS:这不是新行为,但是已经存在了很长时间(甚至在Firefox被称为Firefox之前)。

PS: To give an example, you are allowed to do something like this, only, ie close a window returned from window.open : PS:举个例子,只允许您做这样的事情,即关闭从window.open 返回的窗口:

var w = window.open("http://google.com");
setTimeout(function() { w.close(); }, 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM