Javascript – Why is jQuery unload not working in chrome and safari

javascriptjquery

unload function in jQuery works fine in Firefox but not in chrome and safari. please check this fiddle in chrome and Firefox. http://jsfiddle.net/jeevankk/Gywnw/2/ . Alerts a message when the page is refreshed.

$(window).unload(function() {  
        alert("Unload");  
});‚Äč  

Best Solution

This should work to show a confirmation when the users leaves, this is also not part of any standard.

$(window).on('beforeunload ',function() {
    return 'Are you sure ?';
});
Related Question