Disable browser back button using JavaScript

Introduction

 
Suppose in our application we have two web-pages namely first.aspx and second.aspx and let us imagine a situation that someone is redirecting to second.aspx from first.aspx and our requirement is that if we click on the backward button of the browser then this will not allow us to get back to first.aspx page.
 
To achieve this we need to put the following piece of code in the head section of first.aspx.
  1. <script type = "text/javascript" >  
  2.     function preventBack() { window.history.forward(); }  
  3.     setTimeout("preventBack()", 0);  
  4.     window.onunload = function () { null };  
  5. </script> 
Now, run your application and check it out..