Reputation: 9277
I would like to understand more about how to capture if a user click on the back button of the browser, and what are the basic tecniques to handle it.
As an example of this do you know how to redirect (for instance) to the user to the home page if the back button is pressed?
Upvotes: 0
Views: 738
Reputation: 5641
You can add a function to document onKeyPress:
document.onkeypress = myKeyPressHandler;
// NOTICE: IS NOT a good idea to change the behabiour of backspace
function myKeyPressHandler() {
if (window.event && window.event.keyCode == 8) {
// Handle backspace
// I. E. Go to the home page
window.home(); //
}
}
Actually changing the default beahabiour of backspace is not a good practice and you should avoid doing it unless you have very good reason or you will confuse your users.
Upvotes: 0
Reputation: 114377
You can't and you shouldn't. Users expect their back button to work in a certain way, changing this breaks this behaviour. Bad, bad.
Upvotes: 5