如何防止Firefox中的javascript关闭窗口/选项卡?

时间:2012-02-26 14:10:09

标签: javascript firefox firebug

我正在使用firebug调试网站。该网站打开一个窗口,执行一些操作,然后关闭它。这使我失去了所有的萤火虫网历史。除了更改代码之外,有没有办法阻止javastript在完成后关闭窗口?

2 个答案:

答案 0 :(得分:4)

您可以重写open方法,该方法会添加beforeunload个事件。看看下面带注释的代码+ bookmarklet:

代码:

javascript:(function(w){
    var o = w.open;       /* Stores original `window.open` method */
    w.open = function() { /* Catches all window.open calls*/
        var x = o.apply(w, arguments); /* Calls original window.open */
        /* Bind beforeunload event */
        x.addEventListener('beforeunload',function(e){e.preventDefault()},true);
        return x;
    }
})(window);

小书签:

javascript:(function(w){var o=w.open;w.open=function(){var x=o.apply(w,arguments);x.addEventListener('beforeunload',function(e){e.preventDefault()},true);return x;}})(window);

答案 1 :(得分:3)

我没有尝试过使用它,但是在FF中有一个设置可以让你做你想做的事。

在网址栏中输入about:config,然后按Enter键。发出警告后,您将看到配置选项列表。搜索dom.allow_scripts_to_close_windows并将其值设置为false。

相关问题