Search...

Thursday, February 16, 2012

Disable back button in browser using jQuery


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Disable back button in browser Page</title>
    <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
   <!--Free downloads on www.jquery.com-->
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Copy paste this code in each page where you want to disable back button of browser, if you are using master page and you want to disable every child page of that master page in such case copy paste this code in master page.
</h1>
    </div>
    </form>
</body>
</html>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
     noBack();
});

function noBack() {
    window.history.forward(1);
    }
</script>

********************************************************************************


using System;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}


3 comments:

Anonymous said...

tried that, not working ...

Anonymous said...

I'm using jsf 2.0, when i click the back button, it just goes back???

Kaushik Kumar Mistry said...

Despite of using
window.history.forward(1);
Use
window.history.forward();