views:

5516

answers:

8

How to disable browser's BACK Button (across browsers)?

+26  A: 

Do not disable expected browser behaviour. Make your pages handle the possibility of users going back a page or two; don't try to cripple their software.

Jonathan Fingland
+1  A: 

You should be using posts with proper expires and caching headers.

epascarello
+4  A: 

This question is very similar to this one...

You need to force the cache to expire for this to work. Place the following code on your page code behind.

Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
RSolberg
Note that making the page un-cacheable does not achieve what the OP wanted: to disable visiting pages using the back button.Even if a browser obeys no-cache when using the back button (which browsers are not obliged to do AFAIK) they still provide a way to reload that page (usually after showing a warning dialog). So if you really don't want your users going back to that page, this may be worse, since the request for that page will HAVE to make its way all the way to the origin server.You will need something server-side to detect that the page has been revisited. Headers can be ignored.
thomasrutter
+7  A: 

Others have taken the approach to say "don't do this" but that doesn't really answer the poster's question. Let's just assume that everyone knows this is a bad idea, but we are curious about how to do it anyway...

You cannot disable the back button on a user's browser, but you can make it so that your application breaks (displays an error message, requiring the user to start over) if the user goes back.

One approach I have seen for doing this 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.

thomasrutter
A: 

Refer example below

Disable browser back button

.

+1  A: 

If you rely on client-side technology, it can be circumvented. Javascript may be disabled, for example. Or user might execute a JS script to work around your restrictions.

My guess is you can only do this by server-side tracking of the user session, and redirecting (as in Server.Transfer, not Response.Redirect) the user/browser to the required page.

devio
+3  A: 

I think, the better question is: how can I do smth. without disabling back button? If you want to disable browser's functions, your project is in a wrong way :)

Sergey Kovalenko
A: 

Instead of trying to disable the browser back button it's better to support it. .NET 3.5 can very well handle the browser back (and forward) buttons. Search with Google: "Scriptmanager EnableHistory". You can control which user actions will add an entry to the browser's history (ScriptManager -> AddHistoryPoint) and your ASP.NET application receives an event whenever the user clicks the browser Back/Forward buttons. This will work for all known browsers

Corne