How to Disable Back Button for Web Page? - Handling Logout Issue


How to Disable Back Button for Web Page? - Handling Logout Issue

javascript - Disable browser "back" button

I am facing issue in my application's logout scenario. After the user login into website and then do logout, which leads back to login page. But the problem is now, from this login page, If I click the browser back button then It again takes the user back to the previous visited page as if logged in.

disable back button, java script in browser,logout,logout button,issue, an example

Actually the back button works by stepping through the history of HTTP requests which is maintained by the browser itself. This history is stored in browsers cache that consists of the entire page content with resources like image and scripts. 

This enables browser to navigate backwards and forwards through the browser history and have each page displayed instantly from cache without the delay of having it retransmitted over the internet from the server. Find the source code below :-

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>Disable Back Button for Web Page</title>

    <script type="text/javascript">window.history.forward();function noBack(){window.history.forward();}</script>

<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
    <form id="form1" runat="server">
        Testing ..

  • Set Response Cache settings in code-behind file on Load for a page

      // Code disables caching by browser.

  • Set META tag for HTTP cache settings in your ASPX page header
    <meta http-equiv="Cache-Control" content="no-cache" />

    <meta http-equiv="Pragma" content="no-cache" />

    <meta http-equiv="Expires" content="0" />

Note:- This would not work if one disables JavaScript.

Download source code Click here ..

How to Disable Back Button for Web Page? - Handling Logout Issue Reviewed by Ravi Kumar on 7:00 PM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form


Email *

Message *

Powered by Blogger.