Reputation: 17566
I have a few links in my page and I want to call a function when the page is trying to reload.
I tried
$(window).unload(function() {
alert('Handler for .unload() called.');
});
It is not working.
Upvotes: 0
Views: 12224
Reputation: 1
window.onbeforeunload = unloadMessage;
function unloadMessage() {
//do your codeing here...
}
Upvotes: 0
Reputation: 7856
Console: Blocked alert('Handler for .unload() called.') during unload.
(in Chrome)
I assume this is blocked for user-experience reasons.
If you try console.log('Handler for .unload() called.');
the call is made successfully.
Edit: see $(window).unload is not firing
Upvotes: 4