Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Back button

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?
1 Solution
You can't
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.
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){
scrollbars, toolbar,resizable,directories");
// --></script>

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

                 javascript:openNewWindow(' URL ')

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


Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 http://www.bedrockcomputers.demoin.co.uk/faq.html

mshireAuthor Commented:
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...
To get a page to refresh every time include the following meta tag in your headers.

<meta http-equiv="Pragma" content="no-cache;>
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

<META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://mydomain.com/myfile.html">

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

printf("Location: www.mydomain.com/myfile.html \n\n");

(thats suitable for C and Perl and for ASP


Sorry about the link it should be http://www.bedrockcomputers.demon.co.uk/faq.html

Did that solve your problem.

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.

Ironwolf: Did you really have to post this as an answer! BTW turn off javascript and it fails.
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now