Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pain of browser back button [duplicate]

Is there any way using JavaScript(or something else) to detect/prevent that user clicked on browser back/forward button ?

I would like to know about the common practice to deal with this issue. This is really pain especially in the work flow like ordering.

like image 551
Anil Namde Avatar asked Feb 25 '10 17:02

Anil Namde


3 Answers

Actually preventing the user from using the back or forward button is bad usability and will frustrate users a lot - to be blunt, it's passing a developer problem back to the user.

I think the Post/Redirect/Get pattern, coupled with window.onbeforeunload in javascript (like SO uses) would be really useful for your circumstances.

like image 54
Gavin Miller Avatar answered Nov 18 '22 05:11

Gavin Miller


look into a history manager. something like this:

http://code.google.com/p/reallysimplehistory/

you can make the back button actually do something useful, like going back to previous (valid) state, if possible.

like image 24
mkoryak Avatar answered Nov 18 '22 07:11

mkoryak


If you build a one page web app (meaning a single page is loaded, then all changes are done dynamically in that page with Javascript) you have options:

When the user clicks the back button, you leave the page, since it's the only one, and you can warn the user through the event window.onbeforeunload

And then, if you need/want more control of the back/next button behaviour, you can add a hash( # ) key to handle that.
See my answer to that question: Change the get parameters in the address bar in jquery

like image 1
Mic Avatar answered Nov 18 '22 06:11

Mic