简体   繁体   中英

Stopping the user from using “Back” and “Forward” button of the browser

I am developing a Web App using JSF 2.0 and I have developed a Navigation panel which user will have to use for navigating through the pages. The panel is woking fine. But at the same time I do not want user to use "Back","Forward" of the browser for the navigation. My idea is to if user hits any one those button I'll invalidate the session and show him a info page. Not sure how to aschieve this in JSF 2.0 , JavaScript is a option but I wonder whether JSF has any API support for this???

Don't prohibit the user from using the controls with which they are familiar. First, it presents many technical challenges, but more importantly, it deviates from very, very common paradigms that users expect.

It's acceptable to manipulate the browser history in some cases, and in very select cases it is acceptable to prompt the user before leaving a screen (such as a business application where work might be lost when the user navigates).

It might be appropriate to perform a check with JavaScript prior to leaving the page if the user risks losing significant work. You could then prompt the user, and if they elect to navigate, your server code could check the referring URL and determine from a parameter what flow the user had taken.

Regarding specific technology; checking a query string variable is easy with nearly any server technology (and JavaScript with or without jQuery will work for any client-side logic).

Again, avoid this unless there is no other alternative.

This discussion has information on disabling the back button (why it is not a good idea, and possible alternatives and options).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM