Click here to Skip to main content
15,894,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

can one here please tell me know the solution for disabling the back button or make back button to stop working or redirect to login page on back button click when user logs out from the application.

i am searching for too much time but not getting the exact answer.

Thanks.
Posted
Updated 19-Jun-13 22:08pm
v2

JavaScript
<script type="text/javascript" language="javascript">
       window.onload = function () {
           noBack();
       }
       window.history.forward();
       function noBack() {
           window.history.forward();
       }
   </script>


HTML
<body  onpageshow="if (event.persisted) noBack();">


in body tag of your page please add this code and in javascript too.
this will prevent user from going to previous page..
 
Share this answer
 
More easier solution:

Use the below code on the page(head) which you want to prevent to be landed using back button


C#
<script type="text/javascript">
  function preventBack() { window.history.forward(); }
  setTimeout("preventBack()", 0);
  window.onunload = function() { null };
</script>
 
<script language="JavaScript" type="text/javascript">
  javascript: window.history.forward(1);
</script>


You are done..

Regards.. :laugh:
 
Share this answer
 
thanks to al...:)l . i got my solution by using .

C#
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
 
Share this answer
 
v2
i am still getting teh issue .

used the below code.

C#
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();


but after logout its still going to the recently opened page on clicking browser back button .

please let me know the actual solution if there posses any.
 
Share this answer
 
v2

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