How To Disable Browser Back Button In Asp.Net Using Javascript

How To Disable Browser Back Button In Asp.Net Using JavaScript

Today i am working on some project, in that i have requirement of disabling browser back button.To do so i searched Google and finally i got to know that we can do this by using JavaScript.You just have to include a JavaScript on your page HEAD section.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="disable back button in browser.aspx.cs" Inherits="disable_back_button_in_browser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>Untitled Page</title>
<script type = "text/javascript" >
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
<form id="form1" runat="server">
<h1>Hi this is a test page</h1>
<a href ="index.html">Diable Back Button</a>

In this page when you click on Disable Back Button link, it will refresh the page instead of redirecting. You can also try this in HTML pages, it is working fine in HTML also.