Monday, August 2, 2010

Prevent Pages from going to history on Back Button click using Javascript

Hi we can prevent the  pages ability to go back by using java script. Suppose From Default.aspx page we go to Default2.aspx and we dont want to go to default.aspx from default2.aspx. for this we can place make place javascript on  default.aspx.
 
Place this  between head tags of Default.aspx.
     <script type = "text/javascript" >
function disableBackButton()
{
window.history.forward(1);
}
setTimeout("disableBackButton()", 0);

   </script>

 call this script in body load and unload events so that it will work on all browsers.


<body onload="disableBackButton();" onunload="disableBackButton();">

5 comments: