Thursday, 7 March 2013

Disable Browser Back Button Functionality using JavaScript in ASP.Net

Solutions 1:  
 
Suppose there are two pages Main1.aspx and Main2.aspx and Main1.aspx redirects
 to Main2.aspx

Hence to prevent user from visiting Main1.aspx using Back Button you will need
to place the above script in the head section of Main1.aspx as shown below. 

<script type = "text/javascript" >
         function preventBack() { window.history.forward(); }
         setTimeout("preventBack()", 10);
         window.onunload = function() { null };
 

    </script>


I have tested the script in the following browsers:

1.     Internet Explorer 5.55
2.     Internet Explorer 6
3.     Internet Explorer 7
4.     Mozilla Firefox 19.0
5.     Opera 9
6.     Safari 4
7.     Google Chrome

No comments:

Post a Comment