How to: disable back button?

How to: disable back button?

  
Hi guys,
Has anyone been requested to block the browser back to button?
I’m trying to "disable"/inutilize the browser back button, so that the user may not go back. I’ve tried the following approaches:

·         window.history.forward() - Result: it the same as clicking in the next button of the browser. So if you click back, the previous page will load, the preparation will run (not even IsLoadingScreen() avoids) and then move forward to the page were you were before hitting back. No good!
·         Change the URL on load: Terrible, this is a new request to the url, besides click twice in the back button and you’re already on the previous page, No good!
·         Have a proxy page between pages (the proxy page would redirect to the correct page): doesn’t work, the browser redirects to the previous loaded page, No good!
·         Add the metatags to (try) avoid the browser to cache the pages: No good!
                o   <meta http-equiv="Expires" CONTENT="0">
                o   <meta http-equiv="Cache-Control" CONTENT="no-cache">
                o   <meta http-equiv="Pragma" CONTENT="no-cache">
·         Try to analyze how homebanking sites deal with it (some don’t deal with it at all);
 
Let me know if you have faced & solved this kind of problems!
Ruben,

The only thing I learned about the back buton, don't start with it :).

Don't know what you're trying to achieve, but if it's about a page the user isn't allowed to visit anymore, do this by code and redirections (catch the user in the preparation and check with something (session variable) if he is allowed in that page, if not use a destination).

Kind regards,
Evert

Try to search Master Back button here http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
 

Definitely worth a try!

Thank you, Dung Che Tan.
Hi guys,

Sorry to revive an old thread, but recently we ran into a similar requirement so I'll share our approach in hopes it benefits someone :)

The situation we were trying to solve was going back to a stale page with outdated form data and repeating actions, which cause errors. For example, resubmitting a request that has in the meantime moved on in the process.
Another example is when the user logs out, then hits back and still gets a page, although he should be redirected to the login page.

First of all, I agree with the "don't mess with the Back button" approach. It's a standard button, and disabling it or making it do different things should be avoided.
So we didn't disable it.

What we did was this:
- Add a hidden input to the page - initialize it to some value (for example 'no') - so when the page is rendered by the server it always has a 'no'
- Add a bit of Javascript to the page ready event to:
  - Check that value - if it's not what you'd expect from the server (in our case, <> 'no'), force refresh the page (see below)
  - If it is still set to what you'd expect from the server, change it (in our case to 'yes') and do nothing else

This way, when you hit Back, the page ready event is triggered but the contents of the input is 'yes' because this page isn't fresh from the server (our JS set this value to 'yes' when it was previously rendered) so our JS now forces a refresh of the page, which should solve all our problems.
If the user logged out, the refresh will throw a security exception and send him to the login page, as expected.
If he submitted the form already, the refresh will update the form with the current data (and if the state is not editable, appropriate errors are shown/user is redirected).

Hope this is of some use. I attached an espace that contains an example implementation of this.

Cheers,
Daniel