Possible Duplicates:
How do I stop the Back and Refresh buttons from resubmitting my form?
Disable browser’s back button
Env: jQuery,richfaces
How to disable back button navigation (in the menu bar) on certain pages of the user interface.
You cannot disable the back button on a user's browser. It's a fundamental feature of browsers which can't be overridden.
You can make it so that your application breaks (displays an error message, requiring the user to start over) if the user goes back. It's a bad idea to do this, because it is really an admission that you didn't take the back button into account when you designed the application. Every application, even order forms, shopping carts, online banking etc, if designed correctly should be able to use the back button. If they can't, it's a failure on the part of the application developer.
One approach I have seen for deliberately breaking the back button use is to pass a token on every URL within the application, and within every form. The token is regenerated on every page, and once the user loads a new page any tokens from previous pages are invalidated. When the user loads a page, the page will only show if the correct token (which was given to all links/forms on the previous page) was passed to it.
The online banking application my bank provides is like this. If you use the back button at all, no more links will work and no more page reloads can be made - instead you see a notice telling you that you cannot go back, and you have to start over.
Now, I see this as a lazy way of dealing with a problem. Online banking applications that do this would do it because it's theoretically easier to secure the application if they severely limit the number of circumstances under which someone may arrive at a given page. It is definitely a short-cut compared to making the application work properly in the way that the user should expect, but those who design online banking applications are less focused on usability and more focused on reducing potential attack vectors. They're also probably also stressed out from having to deal with really ancient computer systems and interfaces.
You are not allowed to modify
the window.history
entrys. If you try to set window.history.length
most browsers will throw an exception.
But you can do a more smooth thing with onbeforeunload
like
window.onbeforeunload = function(){
return "are you sure?";
};
that will fire a confirmation box when the user trys to leave the current page (including, history back/forward).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With