我正在使用 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/