javascriptjqueryfirefoxcross-browserwindow.onunload

Jquery: windows.onunload not working in Firefox & Chrome


In Jquery i invoke the method $(window).unload(). it is used for when i closing the browser window i'm return the some values.this function is working fine in I.E. but it is not working in other browsers.

$(window).unload() function is for i.e ? Anybody can help me. thanks in advance.


Solution

  • <script>
    window.onbeforeunload = function() {
        return "Are you sure?";
     };
    </script>
    

    or

    $(window).on('beforeunload', function() {
        return 'Your own message goes here...';
    });
    

    in chorme there are several blocked method on onbeforeunload like alert..
    A chorme example of the debugging console for an alert:

    Blocked alert('My Window is reloading') during beforeunload.
    

    ref1 ref2