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


unload function in jQuery works fine in Firefox but not in chrome and safari. please check this fiddle in chrome and Firefox. . Alerts a message when the page is refreshed.

$(window).unload(function() {  

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