disable back button

Posted on 2001-07-06
Last Modified: 2006-11-17
I'm looking for a script that will disable the Browsers back button for a single page. It will be for IE5.0 and higher only...anyone have one?
Question by:jgla
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

daniel_c earned 88 total points
ID: 6261012
Put this between your <head> and </head> tags.

if (history.length > 0) {



Expert Comment

ID: 6261045
also if you are loading the page yourself (from a link or something) then instead of having a normal link or using window.location.href = "" use window.location.replace("Http://") and the page will not be put into the history list so a user can never get back to it.

LVL 33

Expert Comment

ID: 6261432
There's really no way to do this. Even if there's a way, you should not do it because any users who
surf your site find that he cannot get out of your site once he is in it will never ever wish to visit
it again.

Replace Method

A second method is to make Back button invisible. However, this does not solve the problem totally because
users can always use Backspace to do a back.

Hide Back Button

History Trick
<SCRIPT LANGUAGE=javascript>
var Backlen=history.length;
top.window.location.href ="YourPage.asp";

or this:

<body OnLoad="window.history.forward();">

Read more on this (Server side also here)

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 33

Expert Comment

ID: 6261433
Though there's no way to disable the back button, there's some tricks as described by me above.

LVL 22

Expert Comment

ID: 6262373
Open a new window

<a href="mypage.htm" onClick=";return false;">

Author Comment

ID: 6265664
Perfect. I should have thought of that! But I guess that's why I asked.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question