Search code examples
javascriptjqueryfirefoxwindow

Firefox:4.0 window.onbeforeunload works when closing tab but not on closing the complete window


I am facing a wired scenario in Firefox 4. When I close the tab window.onbeforeunload is getting called. But when user is closing the window by the cross bar it is not getting called.

Is that a bug in Firefox or there is some other thing I need to do . Please check my code.

 $(document).ready(function(){
       window.onbeforeunload = function(){signout()};   
    });
 window.onbeforeunload = function(){signout()};     

Even writing this code outside document.ready is also not working. The same code is working on chrome.

The scenario get's even wired when their are more than one tabs are opened and then user closes the window (not the tab) by cross bar. In this scenario , Firefox asks the user to confirm that he is closing two tabs and after that my code works !!!. This is quite surprising my code does not work only when my page is the only tab and the user closes the window.


Solution

  • There's a thread on it here:

    window.onunload only fires when a tab is closed in firefox, not the entire browser

    It looks like it was a feature around that time to prevent unscrupulous websites from preventing browser being fully closed. I wouldn't be surprised if this is still the case, but the only way to find out is to try on a more current version of Firefox.