Disable Browser Back Button

It is a common question for developer how to to prevent user’s from going to previous page using Browser Back button.
You can do it in various way:

Javascript Codesnippet1:

<script type = "text/javascript" >
function disableBackButton()
setTimeout("disableBackButton()", 0);

For internet explorer: <body onload="disableBackButton()">
If you are using firefox then use <body onunload="disableBackButton()"> instead of onload.

For Server side:
C#-> Asp.net 2.0

ASP.NET 2.0 (there is a new HttpCachePolicy class) :

    * Code disables caching by browser. Hence hitting the back browser button
    * causes the Page_Load event to fire again.
Response.Cache.SetExpires(DateTime.Now); //or a date much earlier than current time


Popular posts from this blog

How can I get a value of a property from an anonymous type (C#)

The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

"This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."