views:

4070

answers:

13

So the SMEs at my current place of employment want to try and disable the back button for certain pages. We have a page where the user makes some selections and submits them to be processed. In some instances they have to enter a comment on another page.

What the users have figured out is that they don't have to enter a comment if they submit the information and go to the page with the comment and then hit the back button to return to the previous page.

I know there are several different solutions to this (and many of them are far more elegant then disabling the back button), but this is what I'm left with. Is it possible to prevent someone from going back to the previous page through altering the behavior of the back button. (like a submit -> return false sorta thing).

Due to double posting information I can't have it return to the previous page and then move to the current one. I can only have it not direct away from the current page. I Googled it, but I only saw posts saying that it will always return to the previous page. I was hoping that someone has some mad kung foo js skills that can make this possible.

I understand that everyone says this is a bad idea, and I agree, but sometimes you just have to do what you're told.

+1  A: 

Disabling the back button seems kind of a "brute force" approach.

Another option would be that you could jump out to a modal dialog that doesn't have command buttons, walk users through the workflow, and close the dialog when the process is complete.

Guy Starbuck
I would completely agree with you, but I have been told this is what I am stuck with.
Kevin
You are not stuck with it you -- you can't be. It is not a viable, valid or ethical solution. FIX THE CODE
lordscarlet
+1  A: 

Could you move the comment to the previous page and make it a required field there?

Disabling the back button will not work.

Joel Coehoorn
+11  A: 

4GuysFromRolla did a thorough examination of "Disabling the Back Button."

http://www.4guysfromrolla.com/webtech/111500-1.shtml

I recommend that you read that article, they also tell you why it will not work (in all scenarios).

Espo
I recommend that you don't. It's two pages long and the last line is: "After my exhaustive search I found that there is still no way of truly disabling the back button for all cases."
Keith
I suspect that was Espo's point exactly.
Jouni K. Seppänen
I read that article earlier today. This was "thorough examination" where the author starts out saying he was surprised to learn anyone would ever want to do that.
BobbyShaftoe
If you find yourself wanting to disable the back button, you're doing something wrong.
jeffamaphone
+1 excellent link, thanks!
Marco Demajo
+2  A: 

Do you have access to the server-side source code? If so, you can put a check on the first page that redirects to the second page if the information has been submitted already (you'll need to use sessions for this, obviously). At a former job, this is how we handled multi-step applications (application as in application for acceptance).

Brian Warshaw
A: 

There simply is no reliable way to do this. You cannot guarantee that 100% of the time you can stop the user from doing this.

With that in mind, is it worth going to extremely exotic solutions to disable "most" of the time? That's for you to decide.

Good luck.

Matt Dawdy
+1  A: 

Because of the security isolation of javascript in the browser, you cannot change what the back button does.

Perhaps you could store something in the user's session that indicates that a comment is needed, and have any page in the app that the user tries to load redirect to the comment page?

What if the user closes their browser when he/she gets tot he comment page?

I know that you have not been given a choice here, but since what they are asking for seems to be impossible...

Perhaps you could just not consider the item as completed until the user enters comments. Thus, you would need to keep track of both in-progress items and completed items, and make that distinction in the UI, but this might be the most robust method.

Or just put the comment field on the form page?

pkaeding
+2  A: 

I've seen this before:

window.onBack = history.forward();

It is most definitely a dirty hack and, if at all possible, I would attempt to not disable the back button. And the user can probably still get around it quite easily. And depending on caching, there is no telling if the server code will be processed or if the cached page with JavaScript will run first.

So, yeah, use at your own risk :)

David Mohundro
Would your code break this "requirement"?"Due to double posting information I can't have it return to the previous page and then move to the current one. I can only have it not direct away from the current page"
Espo
+4  A: 

Nah, you're doomed. Even if you pop the page up in some different browser and hid the back button, there's always the Backspace key.

The problem with marketing guys and analyst types is that some of them do not understand the fundamental concept of the web being stateless. They do not understand that the page is totally, totally unaware of the browser using it and absolute control of the browser is totally outside the capability of web pages.

The best way to discourage your users to hit the back button is to make sure that your page loses all its data when they press back, e.g., the comment page is the only point where the data can be saved, and if they do press the back button they have to do everything all over again (think along the lines of pragma: nocache).

Users will complain, sure, but they are the reason that this godforsaken requirement exists, right?

Jon Limjap
+30  A: 

Don't do this, just don't. It's bad interface design and forces the user's browser to behave in a way that they don't expect.

I would regard any script that successfully stopped my back button from working to be a hack, and I would expect the IE team to release a security-fix for it.

The back button is part of their program interface, not your website.

In your specific case I think the best bet is to add an unload event to the page that warns the user if they haven't completed the form. The back button would be unaffected and the user would be warned of their action.

Keith
Keith is spot on. The 4 Guys article previously referenced even ends with: "After my exhaustive search I found that there is still no way of truly disabling the back button for all cases." Doh! I don't need to read two articles to read that last!
rp
agreed Keith. We've been through roughly the same situation at my work and after a long time we realized it would have been easier to refactor the application to not need the back button disabled.
Jared
+3  A: 

What the users have figured out is that they don't have to enter a comment if they submit the information and go to the page with the comment and then hit the back button to return to the previous page.

Then they are probably also smart enough to type 'no comment' into the comments field.

You can try to force people to add comments, but you will probably just end up with bad unusable software, annoyed users, and still not get comments. This is usually a good time to take a step back and reconsider what you are doing from the users' point of view.

Peter Hilton
This also just screams of some bad code. Why are people able to bypass the comment with a click of the back button? You don't solve bad code by hacking the user's browser.
lordscarlet
+1  A: 

If you disable my back button I will hunt you down and beat you up.

Lazy programmers want to disable user features that cause their code grief because they are too damn lazy to change their code handle it accordingly. Catch my drift?

If you can't handle a little back action, then write your own browser and force your users to use it. Ha!

Josh Stodola
+1  A: 

You should secure your application against double submission instead of breaking user interface to hide the bug.

porneL
A: 

AS a simple solution: try this one. Insert an update panel and a button in there and use javascript to hide it and then press it on page load. Yes I understand that it will cause your page to post back on load and may not work if javascript is disabled but certainly will help you achieve a half decent response to the back button issue. Andy

Andy