Reputation: 1570
How do I listen for a browser back button click and call a function that I've defined and disable the normal behaviour of the back button? I'm using jQuery.
Upvotes: 2
Views: 25184
Reputation: 9703
You could play with :
$(window).unload( function () { alert("Bye now!"); } );
But this will be trigered when the user clicks a link that goes to another page , types a new address in the address bar or ... basicly it will be trigered whenever the user leaves the current page . I don't think you can stop the user from going away from you're page tough .
UPDATE:
unload() is now deprecated from jquery 1.8
Upvotes: 1
Reputation: 21864
jQuery history plugin helps you to support back/forward buttons and bookmarks in your javascript applications. You can store the application state into URL hash and restore the state from it.
Upvotes: 2