Javascript window.close(), self.close() 不适用于 mozilla firefox

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3465191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:45:14  来源:igfitidea点击:

window.close(), self.close() not working on mozilla firefox

javascript

提问by Sachin

I want to close window on logout. I have used

我想在注销时关闭窗口。我用过了

  • window.close(),
  • self.close(),
  • var win = window.open("","_self"); win.close();
  • window.parent.close();
  • window.close(),
  • self.close(),
  • var win = window.open("","_self"); win.close();
  • window.parent.close();

These all above i have used that all work in IE but in Mozilla Firefox not working.

以上所有这些我都使用过,它们在 IE 中都可以使用,但在 Mozilla Firefox 中不起作用。

Please give me solution for that.

请给我解决方案。

Thanks.

谢谢。

回答by Sachin

I tried to review all topics about window.close() and have found that: IE/Chrome/Safari(?) accept closure if we open something on _self, so generally

我尝试查看有关 window.close() 的所有主题,发现:如果我们在 _self 上打开某些内容,IE/Chrome/Safari(?) 接受关闭,所以通常

top.open('','_self',''); top.close();

top.open('','_self',''); 关闭();

does the work. FF (r 19 when writing this) is more strict about this and somehow forbids any probe like above. The good answer was found in related thread, that user must manually allow FF to have solution above working

做这项工作。FF(撰写本文时为 r 19)对此更为严格,并且以某种方式禁止上述任何探测。在相关线程中找到了很好的答案,用户必须手动允许 FF 解决上述问题

about.config -> dom.allow_scripts_to_close_windows = true;

about.config -> dom.allow_scripts_to_close_windows = true;

I was quite desperated, as Customer requested window closure on completed operation.

我非常绝望,因为客户要求在完成操作后关闭窗口。

Big bravo to FF dev team. This is exactly how it should work; pity only is that is hard to find it.

FF 开发团队的大喝彩。这正是它应该如何工作的;唯一遗憾的是很难找到它。

Pawel.

帕维尔。

回答by Sachin

I have found that Firefox can only use window.close()when script has been called to open that window in the first place.

我发现Firefox 只能在首先调用脚本打开该窗口时使用 window.close()

Read herefor more info.

阅读此处了解更多信息。

So if you didn't use a script to open that window, it can't be done.

因此,如果您没有使用脚本打开该窗口,则无法完成。

回答by JB.

Ive been using something like this:

我一直在使用这样的东西:

<head>
<script language="javascript" >
function ddd() {

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");

window.open('http://www.google.com','mywindow','width=400,height=200');
window.close();
}
</script> 
</head>
<body>
<input type= "button" name="new" value="New Window" onClick="ddd()">
</body>

回答by nembleton

Is seems that they are working on Chrome Kiosk ( Fullscreen ) mode. Tried successfully. Up to 19 as of now.

似乎他们正在使用 Chrome Kiosk(全屏)模式。尝试成功。截至目前,已达到 19 个。

回答by Pravin Sharma

Working 100 % for me

为我工作 100%

In Mozilla by default the "dom.allow_scripts_to_close_windows" value which controls the Java Script close window is set to "false". In order to fix this issue change this value to "true"

在 Mozilla 中,默认情况下,控制 Java Script 关闭窗口的“dom.allow_scripts_to_close_windows”值设置为“false”。为了解决这个问题,将此值更改为“true”

Location of the File:

文件位置:

C:\Program Files\Mozilla Firefox\greprefs\all.js

C:\Program Files\Mozilla Firefox\greprefs\all.js

change "dom.allow_scripts_to_close_windows" from "false" to "true"

将“dom.allow_scripts_to_close_windows”从“false”更改为“true”

Example:

例子:

Default value

默认值

pref("dom.allow_scripts_to_close_windows", false);

pref("dom.allow_scripts_to_close_windows", false);

Change it to:

将其更改为:

pref("dom.allow_scripts_to_close_windows", true);

pref("dom.allow_scripts_to_close_windows", true);

2.Close Mozilla browser

2.关闭Mozilla浏览器

3.Try accessing HTML page which has window.close() code snippet

3.尝试访问包含 window.close() 代码片段的 HTML 页面

Note : If you not find "all.js" then go to C:\Program Files (x86)\Mozilla Firefox\defaults\pref\channel-prefs.js and add "pref("dom.allow_scripts_to_close_windows", true);" into "channel-prefs.js" file

注意:如果您没有找到“all.js”,则转到 C:\Program Files (x86)\Mozilla Firefox\defaults\pref\channel-prefs.js 并添加“pref("dom.allow_scripts_to_close_windows", true);” 进入“channel-prefs.js”文件

回答by Gee

This worked for me perfectly:

这对我来说非常有效:

<a href="javascript:window.open('','_parent','');window.close();">Close this window</a>