Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Javascript

Disabling browser's back button

1.91/5 (7 votes)
6 Aug 2013CPOL 69.9K  
Disabling the browser's back button.

Introduction  

A web browser has back and forward buttons to navigate between webpages, whose URLs are stored in the browser's history.

Problem Statement

When you are using web forms and authenticated pages you don't want the end user to use back and
forward buttons of the web browser  to navigate as you will be providing all the navigation
required through your application's menu based on workflow.  

The most common problems an application designer should consider are as follows:

  1. Resubmission of web form data, which might create duplicate entries.
  2. Issues with workflow of the application.  
  3. Compromised application security.

Even though if you somehow tweak the web browser to disable the back and forward buttons, you are destroying the fundamental functionality of the web browser i.e. navigation. You might require back and forward buttons when you are browsing static pages. 

But technically disabling the browser's back button is not possible through webpage code, how ever
there is a workaround for it.

Workaround  

The following workaround should be added in the <head> section your  webpage/master page, where you don't want the user to be revisiting using a browser's back button:

HTML
<script language="javascript" type="text/javascript">
    window.history.forward();
</script> 

Compatibility verified in

  1. Internet Explorer 
  2. Google Chrome  
  3. Mozilla Firefox  
  4. Opera 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)