Search This Blog

Thursday, March 7, 2013

How to disable Back Button using JavaScript..?

There are sometimes requirements when you have to disable your browser back button,so it won't go to previous pages. For example, when you press log-out and then on the current page the back-button or Backspace key should be disabled to maintain security...



So here is a code for javascript.
Put this snipt on  pages when you require this disabled back-button functionality:




<SCRIPT type="text/javascript">                          
 window.history.forward();                               
 function noBack() { window.history.forward(); }         
</SCRIPT>                                                
</HEAD>                                                  
<BODY onload="noBack();"                                 
 onpageshow="if (event.persisted) noBack();" onunload="">