如何在 Mozilla Firefox 3 上使用 Javascript 关闭窗口? [英] How can I close a window with Javascript on Mozilla Firefox 3?

查看:29
本文介绍了如何在 Mozilla Firefox 3 上使用 Javascript 关闭窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过单击按钮关闭显示我的网页的选项卡.但是firefox不允许通过javascript关闭窗口,只要它不是由javascript打开的.如果我将 dom.allow_scripts_to_close_windows 的值设置为true",那么即使是普通的 window.close() 也可以工作.但这不是一个好的解决方案.:(

I need to close the tab which displays my webpage, by the click of a button. But firefox does not allow to close the window by javascript as long as it is not opened by javascript. If I set the value of dom.allow_scripts_to_close_windows to be "true", then even normal window.close() works too. But that is not a good solution. :(

我尝试了其中一个论坛中建议的以下解决方法:

I tried the following workaround suggested in one of the forums:

<script language="javascript" type="text/javascript">
function closeWindow() {
   window.open('','_parent','');
   window.close();
}
</script> 

它应该让浏览器认为它实际上是由 javascript 打开的,但这在 Firefox 3 中不起作用.

It is supposed to fool the browser into thinking that it was actually opened by javascript, but this does not work in Firefox 3.

任何人都可以提出解决方法吗?

Can anyone please suggest a workaround?

推荐答案

function closeWindow() {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
    alert("This will close the window");
    window.open('','_self');
    window.close();
}

closeWindow();

这篇关于如何在 Mozilla Firefox 3 上使用 Javascript 关闭窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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