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
"refresh" action in the Firefox does not fire the unload
event.
We should use onbeforeunload
instead.
Confirm with Firefox version 47, Mac OS X
the unload function of jquery has some problem with browsers..refer the following link http://bugs.jquery.com/ticket/5538
can you elaborate on the problem so that we can find some work around??
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 ?';
});
This is because the unload event is not part of any standard
https://developer.mozilla.org/en/DOM/window.onunload
check the bottom of the page i just linked to.
I found Joseph's comment as the correct answer, So posting this answer.
Dialogs are blocked/prevented during "beforeunload" (with exception to the beforeunload prompt) and "unload" events. Can be confirmed by checking your console.
you can use onfocusout on the body .. but i wouldn't recommend if you are trying to use something like an alert, on this operation, asking the user not to leave your page ..