Back button

Posted on 2000-05-05
Last Modified: 2013-12-25
How can I prevent a user from using the back button?

I have a registration page, when registered I don't won't them pressing the back button and doing it again!

Any ideas?
Question by:mshire
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

Expert Comment

ID: 2781928
You can't

Expert Comment

ID: 2781990
Jagar is right, there is no way you can STOP them from using the back button.  

The best you can do warn them about what they are doing.  Maybe using onbeforeunload() you could give them a choice as to if they really want to leave.

Or, make the registration page a seperate pop-up window with no buttons or bars at all except for the submit button that closes the window on submit.

Expert Comment

ID: 2783206
Open the registration page with the back button disabled.

Here is how to do:

(1) Put following Javascript in your header section
<script language="JavaScript">
 function openNewWindow(url){,"NewWindow","width=625,height=320,status,menubar,
scrollbars, toolbar,resizable,directories");
// --></script>

(2)  Put following around your HREF tags for registration page

                 javascript:openNewWindow(' URL ')

                   Here's an example.........


Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

LVL 11

Expert Comment

ID: 2784695
As has been said before you can't stop them pressing the button, except by opening a new window without any buttons on it.

However you can negate them pressing a back button. Assuming that they are on Page A move to Page C and you don't want them to go back to A.

What you actually do is when they leave Page A they go to page B which is just a redirection to page C.

Now if they press back they will go to B which pushes them back to C immediately.

further details are available at


Author Comment

ID: 2785388
Yeah that sounds like a good idea... if they press the back button after registering, it would load the previous page, find out they are already registered and redirect them. But how do I get the page to refresh even after pressing the back button (the <meta HTTP-EQUIV="EXPIRES" content="0"> doesn't seem to work always)



PS mouatts - that link didn't seem to work...

Expert Comment

ID: 2786069
To get a page to refresh every time include the following meta tag in your headers.

<meta http-equiv="Pragma" content="no-cache;>
LVL 11

Expert Comment

ID: 2788066
Reader is correct that you should use pragma nocache to refresh a page. But to do a redirection you should use the Location Message (from HTTP) or refresh with a 0 type from a META tag. ie


But if this redirection is out of a CGI then you should use the following

printf("Location: \n\n");

(thats suitable for C and Perl and for ASP


Sorry about the link it should be

LVL 11

Expert Comment

ID: 2815976
Did that solve your problem.


Accepted Solution

Ironwolf earned 100 total points
ID: 2892837
If you put this code on the top of your registration page:

<script language=JavaScript>

then every time they go back to this page, using the back button, a right click, alt+backArrow, or any other method, it will automatically push them forward to the page they came from.

You can put this on every page of your web if you want them to only be able to navigate your page through the links.

This method is very effective when you have a data-driven web where the data is constantly updated and you want to make sure it is refreshed upon each viewing.

LVL 11

Expert Comment

ID: 2918190
Ironwolf: Did you really have to post this as an answer! BTW turn off javascript and it fails.

Expert Comment

ID: 103422
Not that anyone will care, but if you code the page as an hta instead of regular html, back will simply be disabled as a feature in the user's browser.

This, of course, brings lots of other issues to the table.

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This video teaches users how to migrate an existing Wordpress website to a new domain.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 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