Jquery: windows.onunload not working in Firefox & Chrome

ELAYARAJA picture ELAYARAJA · Jun 25, 2013 · Viewed 7.1k times · Source

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.

Answer

Alessandro Gabrielli picture Alessandro Gabrielli · Jun 25, 2013
<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