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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With