Reputation: 2915
How do I detect that a user is navigating away from my page? Kind of like stackoverflow does, if you have started writing a post.
I have tried $(window).unload()
in jQuery, but I can't get it to work.
This statement is not entirely true, in IE9 it works, in fact a bit too well. It also pops up, if the page is refreshed. But in Chrome, nothing triggers.
Upvotes: 6
Views: 7158
Reputation: 176956
Include the jQuery library in your code, and then try out this
$(window).bind('beforeunload', function(){
return 'DataTest';
});
Upvotes: 10