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

标签 javascript firefox firebug

我正在使用 Firebug 调试网站。该网站打开一个窗口,执行一些操作然后关闭它。这导致我丢失了所有的 Firebug 网络历史记录。除了更改代码外,是否有任何方法可以防止 javastript 在完成后关闭窗口?

最佳答案

您可以重写open 方法,它会添加一个beforeunload 事件。看看下面的注释代码 + 书签:

代码:

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);

关于javascript - 如何防止 firefox 中的 javascript 关闭窗口/选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9453761/

相关文章:

javascript - 服务 vs Controller vs 外部 js 将常用方法放入 AngularJS 中

javascript - 未通过 jQuery/CoffeeScript 设置所选值

html - 旋转的 div 在 Chrome 和 Firefox 中呈现不同

javascript - 使用 Firebug 时如何防止页面更改

javascript - JSON 对象获取长度

javascript - RegEx 问题 - 删除 : and ~ 之间的所有内容

javascript - 使用 Firefox 聚焦于父窗口

html - 在 Firefox 中使用 tab 时删除 <html> 的轮廓

javascript - 在 Firebug/Chrome 中获取从一个断点到另一个断点的 Javascript 或 jQuery 堆栈跟踪?