Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

i want to block back button in those browsers with different version like IE ver:10 +,firefox ver:30 + ,chrome ver: 35 +.

i tried some code in javascript that will not work.here code below:

example1 :
javascript:window.history.forward(1);

example 2 :

<script type = "text/javascript" >

   function preventBack(){window.history.forward();}

    setTimeout("preventBack()", 0);

    window.onunload=function(){null};

</script>



pls give some good solution for this asap.
Posted

 
Share this answer
 
Hi,

The other thing that you can try is clear the with the following code assuming that yours is an mvc application

C#
public class NoCache : ActionFilterAttribute
  {
      public override void OnResultExecuting(ResultExecutingContext filterContext)
      {
          filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
          filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
          filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
          filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
          filterContext.HttpContext.Response.Cache.SetNoStore();
      }
  }
 
Share this answer
 
Windows Forward[^]
Manipulate Browser History[^]
Disabling browser back button, you should not or say you cannot. Check the links I have provided. These just maipulate with the browsers history letting you feel the Back button is disabled but not exactly.
Window.History.Forward() is a simple one. Which prevents the user going back to previous page. The second link helps you find more methods to manipulate on this.
Hope this helps.
Post back your queries if any.
Thanks.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900