Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent javascript inside firefox from closing a window/tab?

I am debugging a website using firebug. The website opens a window, performs some operations and than closes it. This causes me to lose all of the firebug net history. Is there any way to prevent javastript from closing the window after its done, except changing the code?

like image 349
Arsen Zahray Avatar asked Feb 26 '12 14:02

Arsen Zahray


2 Answers

You can rewrite the open method, which adds a beforeunload event. Have a look at the annotated code + bookmarklet below:

Code:

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

Bookmarklet:

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);
like image 173
Rob W Avatar answered Sep 28 '22 09:09

Rob W


I haven't tried to use it, but there's a settings in FF which supposedly lets you do what you wish.

Type about:config in the url bar and press enter. After a warning you'll see the list of config options. Search for dom.allow_scripts_to_close_windows and set its value to false.

like image 23
Bijou Trouvaille Avatar answered Sep 28 '22 07:09

Bijou Trouvaille