开发者

pain of browser back button [duplicate]

开发者 https://www.devze.com 2022-12-21 11:46 出处:网络
This question already has answers here: Intercepting call to the ba开发者_开发问答ck button in my AJAX application
This question already has answers here: Intercepting call to the ba开发者_开发问答ck button in my AJAX application (11 answers) Closed 8 years ago.

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


Nope this is not possible, you can not usurp the browsing experience from a user, but hope there should be a work around to this....


As far as I know, not, but you can use the window.onbeforeunload event to warn users not to go away, when risking data loss. Please bear in mind this doesn't work on Opera.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号