65.9K
CodeProject is changing. Read more.
Home

Disabling browser's back button

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.91/5 (7 votes)

Aug 6, 2013

CPOL
viewsIcon

69932

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:

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

Compatibility verified in

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