简体   繁体   English

阻止用户使用浏览器的“后退”和“前进”按钮

[英]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. 我正在使用JSF 2.0开发Web应用程序,并且已经开发了一个“导航”面板,用户必须使用它来浏览页面。 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??? 不知道如何在JSF 2.0中做到这一点,可以选择使用JavaScript,但我想知道JSF是否对此有任何API支持???

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. 如果用户冒着丢失重要工作的风险,那么在离开页面之前使用JavaScript执行检查可能是合适的。 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. 然后,您可以提示用户,如果他们选择导航,则服务器代码可以检查引用URL,并根据参数确定用户采取的流程。

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). 几乎所有服务器技术都可以轻松地检查查询字符串变量(具有或不具有jQuery的JavaScript均可用于任何客户端逻辑)。

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). 此讨论提供了有关禁用后退按钮的信息(为什么这不是一个好主意,以及可能的替代方法和选项)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Chrome扩展程序中,确定用户是否单击了浏览器的“后退”或“前进”按钮 - In Chrome extension determine if the user clicked the browser's Back or Forward button 如何通过单击angularjs中的浏览器后退/前进按钮来后退/转发用户的历史记录 - how to back/forward user 's history by clicking the browser back/forward button in angularjs 我们如何限制/限制用户使用javascript重新加载页面或浏览器向后或向前 - How can we constraint/restrict the user from page reloading or browser back or forward using javascript 从浏览器按钮前进/后退时如何使网页过期 - How to expire webpage when back/forward from browser button 如何使用浏览器后退按钮阻止用户从收据页面返回? - How to Stop user going back from receipt page using browser back button? JavaScript和浏览器的后退/前进按钮 - JavaScript and the browser's back/forward button React组件在浏览器后退/前进按钮上中断 - React component breaks on browser back/forward button 如何区分浏览器后退/前进按钮? - How to distinguish browser back / forward button? 禁用地址栏和浏览器的前进和后退按钮 - disable address bar and back and forward button of browser 防止从浏览器后退和前进按钮下载 - Prevent Downloads from browser back and forward buttons
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM