Disable Back Button

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Hebbs
Forum Commoner
Posts: 43
Joined: Mon Apr 22, 2002 9:34 pm
Location: Perth, Western Australia

Disable Back Button

Post by Hebbs »

That got your attention didnt it!

Whilst I am aware you cant do this, I want to include a Javascript function that pops up an error message when selecting the back button on certain pages.

I dont want users resubmiting info in one or two scripts by going back then forward again.

Any thoughts?

Hebbs
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post by DSM »

Code: Select all

//cache control
if ($REQUEST_METHOD=='POST') :
   header('Expires: ' . gmdate("D, d M Y H:i:s", time()+1) . ' GMT');
   header('Cache-Control: Private');
endif;
//end cache control
This should stop form info from reposting if vermin, I mean visitors try using the <<Back/Forward>> buttons.
Hebbs
Forum Commoner
Posts: 43
Joined: Mon Apr 22, 2002 9:34 pm
Location: Perth, Western Australia

Back control continued

Post by Hebbs »

Thanks DSM but can you clarify this some more for me?

What should the result be and where does it exactly go in relation to the <head>, <body> of the script etc.

I need to be able to return to the page as I have some error checking that sends the user back when they forget info or put in the wrong data.

My original line of thought was a Javascript reaction that told them not to be stupid and leave the BACK button alone!

Hebbs
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Hebbs, you would put the above header statements AFTER all error checking. Basically, if all the data is valid, then you put those statements.

Note, make sure you don't have ANY HTML or spaces (you don't output anything) before the header() functions.
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

Post by ILoveJackDaniels »

I could be wrong (heheh, wouldn't be the first time :) ), but I think the back button can appear disabled if you want, using a META REFRESH tag with a delay of zero seconds. While that does not actually disable the back button, it does give that appearance, as when the user clicks on it they go nowhere....

Code: Select all

<META HTTP-EQUIV="Refresh"
CONTENT="0; URL=http://www.yoursite.com/newpage.html">
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

jepp, but this wouldn't stop me from using the drop-down-history of my back-button ;)
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

Post by ILoveJackDaniels »

Ok, how's about this then .... a javascript triggered by an onload function in the body tag, that opens the required page in a new window then closes the current window...?

Only problem with that one ie IE's new 'feature' that asks for confirmation before closing windows......
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

I still think the header() approach is the best one. Works all the time.
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

DSM wrote:

Code: Select all

//cache control
if ($REQUEST_METHOD=='POST') :
   header('Expires: ' . gmdate("D, d M Y H:i:s", time()+1) . ' GMT');
   header('Cache-Control: Private');
endif;
//end cache control
This should stop form info from reposting if vermin, I mean visitors try using the <<Back/Forward>> buttons.
Exactly how this works? I've set these headers:

Code: Select all

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
   header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
   header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
   header("Cache-Control: post-check=0, pre-check=0", false);
   header("Pragma: no-cache");
What

Code: Select all

header('Expires: ' . gmdate("D, d M Y H:i:s", time()+1) . ' GMT');
actually does and what

Code: Select all

header('Cache-Control: Private');
means? I want to prevent any caching, are these prevent back buttoning headers going to do some harm to that?
Last edited by 9902468 on Fri Jun 28, 2002 12:37 am, edited 1 time in total.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

A word of warning for anyone thinking about using a javascript refresh for anything if you set it to less than 5 seconds googlebot won't follow it as it will think it's spam, not a major upset but something to be aware of.

I solved a similar problem by passing a hidden variable in the form called used and set it to 1 once someone submitted the form. If there was an error and they needed to go again it was reset to 0. It’s a bit simple but I like simple. :wink:
Post Reply