|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
||||
|
||||
|
Is there a way to DISABLE the BACK BUTTON?
I have a multiple page regstration process for a site that I am developing. In initial beta-testing, I have found some users (even though they are warned not to) have been using the back button in the middle of registration - thereby wreaking havoc on the registration process!
I was wondering if there is a way to disable the back button? TIA! ![]()
__________________
$mybrain = "mush"; ------------------------------------------- http://www.loftsboston.com http://www.gregdawsondesign.com |
|
#2
|
|||
|
|||
|
Use this Javascript method:
replace Method The replace method replaces the current History entry with the specified URL. After calling the replace method, you cannot navigate back to the previous URL using the browser's Back button. Syntax: location.replace(URL)
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
<script language="JavaScript">
window.history.forward(1); </script> |
|
#4
|
|||
|
|||
|
For the method iahmed proposed, you need to put that code at the bottom of each page that you DON'T want the user to be able to go back to or resubmit.
I suggest you use both methods together. |
|
#5
|
||||
|
||||
|
Thanks for the swift reply! I can't seem to get either of these solutions to work.
How do I use the replace method? Do I wrap it in a <script language="JavaScript"> tag? |
|
#6
|
|||
|
|||
|
It can be in a <script></script> block, or you can make it easy.
Try this: <a href="javascript: location.replace('/');">Home Page</a> |
|
#7
|
|||
|
|||
|
Hi.
You might want to look at this too for an alternate solution: http://www.htmlgoodies.com/tutors/nobackbutton.html |
|
#8
|
|||
|
|||
|
Quote:
Hey! This is a little more dynamic method of doing it. I needed the possibility to switch the back buttons function on and of depending on what the client where doing. This is tested in Mozilla firefox and IE, the code is from a separate .js file This will allow you to turn the back buttons function off with the functions ‘blockBackButton()’ And turn it on again with ‘resetBackButton()’ The script uses the get part of the url, but wont permanently change it becoause if the browser get a changed get part of the url, the script will reload the earlier page were the url was unchanged. var ie = (window.navigator.appName == "Microsoft Internet Explorer") ? true : false; function setEventByObject(object, event, func){ if (!ie){ object.addEventListener(event, func, false); } else { object.attachEvent("on" + event, func); } } setEventByObject(win, "unload", exitme); var block = "false"; function blockBackButton(){ block = "true"; } function resetBackButton(){ block = "false"; } function jumpforward(){ if(window.location.href.indexOf("&jumpforward")!=-1) { history.forward(); } } jumpforward(); function exitme(){ if(block == "true") window.location.href += "&jumpforward"; } |
|
#9
|
|||
|
|||
|
Nicely done.
Thank you. Quote:
|
|
#10
|
|||
|
|||
|
About 'win' parameter
hi,
i gone through this code and tried it but i am getting one error that 'win' is undefined so plz tell me what is that win bye Quote:
|
|
#11
|
||||
|
||||
|
First of all, this thread is over a year old, very slim chance you'll get a reply from that poster, seeing he hasn't posted much since then.
Second, whatever way you try to do this (disabling the back button), be ready for the fact it won't work on every browser. Every good browser has ways to disable javascript, and/or settings that determine how much power javascript has. Do no try to limit a users power over his own computer. If I want to go back, for whatever reason, it's my good damn right. If doing that breaks your site, you should write better code, that checks for stuff like that.
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 264
![]() |
|
#12
|
|||
|
|||
|
Block the Back Button
Quote:
Hi, here is a way to get it to work and also let people use the back button after a warning. It also fixes problems with the querystring variables. <script> var ie = (window.navigator.appName == "Microsoft Internet Explorer") ? true : false; window.name = 'test'; function setEventByObject(object, event, func){ if (!ie){ object.addEventListener(event, func, false); } else { object.attachEvent("on" + event, func); } } setEventByObject(window, "unload", exitme); function jumpforward(){ if(window.location.href.indexOf("jumpforward")!=-1) { history.forward(); } } // Block Back Button for this page var block = "true"; function exitme(){ if(block == "true") { if(window.location.href.indexOf("?")==-1) { window.location.href += "?jumpforward"; } else if (window.location.href.indexOf("jumpforward")==-1){ window.location.href += "&jumpforward"; } alert(Please, please don't use the Back button') jumpforward(); } } </script> |
|
#13
|
||||
|
||||
|
i agree with Itsacon, you should be able to use the back button
for another reason you could <script>function ul() {do something to stop you site from being screwed}</script> <body onunload="ul()"> colton22 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Is there a way to DISABLE the BACK BUTTON? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|