Click here to Skip to main content
11,432,119 members (57,632 online)
Click here to Skip to main content

Disabling browser's back button

, 6 Aug 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
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 

License

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

Share

About the Author

Srinivas Kalabarigi
Software Developer (Senior)
India India

Around 8 years of software development experience and involved in analysis, design, development, testing and deployment of enterprise web applications for government, healthcare and banking domain with good exposure to object-oriented design, software architectures, design patterns, test-driven development and agile practices.


Educational Background
  • Post Graduation in Computer Science from Andhra University, India.
  • Graduation in Mathematics, Electronics and Computer Science from Andhra University, India.
  • Diploma in Software Technology from CMC Ltd., India.

Comments and Discussions

 
QuestionThxs for the nice and useful snipet :) Pin
Vendito24WEB7-May-14 1:36
memberVendito24WEB7-May-14 1:36 
QuestionDisabling Browser's Back Button Pin
dgtheboss17-Nov-13 9:17
memberdgtheboss17-Nov-13 9:17 
SuggestionThis is not sufficient and generic way to handle browser back button Pin
Sanjay Gupta (Tech Archit)12-Sep-13 14:58
memberSanjay Gupta (Tech Archit)12-Sep-13 14:58 
SuggestionRe: This is not sufficient and generic way to handle browser back button Pin
VICK8-Jan-14 20:00
member VICK8-Jan-14 20:00 
GeneralMy vote of 1 Pin
HaBiX7-Aug-13 20:36
memberHaBiX7-Aug-13 20:36 
QuestionMy dev side says yes, but my user side says no! Pin
ryanoc3337-Aug-13 3:54
memberryanoc3337-Aug-13 3:54 
GeneralMy vote of 2 Pin
AlexCode6-Aug-13 21:38
professionalAlexCode6-Aug-13 21:38 
GeneralRe: My vote of 2 Pin
Srinivas Kalabarigi6-Aug-13 21:52
professionalSrinivas Kalabarigi6-Aug-13 21:52 
GeneralRe: My vote of 2 Pin
AlexCode6-Aug-13 22:04
professionalAlexCode6-Aug-13 22:04 
GeneralMy vote of 2 Pin
damian-piatkowski6-Aug-13 11:56
memberdamian-piatkowski6-Aug-13 11:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 7 Aug 2013
Article Copyright 2013 by Srinivas Kalabarigi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid