Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
请阅读此处,了解禁用后退按钮的几个选项。
但是:这个问题让我觉得你试图解决错误的问题。
后退按钮是用户期望起作用的按钮。如果禁用它,就会破坏浏览器(从用户的角度来看):在其他地方都有效的东西在您的页面上不起作用。用户会讨厌你的页面并试图避开它。如果他们无法避开该页面,他们会更加讨厌它。
那么您有什么选择:
您可以在用户使用按钮时获取事件。例如,GWT 将应用程序的内部状态保存在虚拟历史事件中。因此用户可以像实际应用程序中的“撤消”一样使用后退按钮。
避免为您的页面创建历史事件。确保标题栏中的 URL 永远不会改变。将所有更改保存到您的服务器上。对于用户来说,页面/应用程序感觉就像一页。当他下次返回时,从服务器上的数据库恢复最后的状态。
这样,用户可以像以前那样使用后退按钮离开您的页面,但仍然不会丢失任何工作。
两者的混合体。例如,堆栈溢出允许您使用链接和后退按钮在页面之间移动。如果您开始编辑页面上的某些内容,当您单击后退按钮时,您会收到警告。
Read here for several options to disable the back button.
BUT: The question makes me feel like you're trying to solve the wrong problem.
The back button is something that the user expects to work. If you disable it, you would break the browser (from the user perspective): Something that works everywhere else doesn't work on your page. Users would hate your page and try to avoid it. If they can't avoid the page, they would hate it even more.
So what are your options:
You can get events when the user uses the button. GWT, for example, saves the internal state of the application in virtual history events. So the user can use the back button like Undo in a real application.
Avoid creating history events for your page. Make sure the URL in the title bar never changes. Save all changes on your server. For the user, the page/application will feel like one page. When he returns next time, restore the last state from the database on your server.
This way, the user can use the back button to leave your page as he is used to but he still won't loose any work.
A mix of the two. For example stack overflow allows you to move between the pages using links and the back button. If you start to edit something on a page, you get a warning when you click on the back button.
只需使用 javascript 在新选项卡中打开您的页面,就像将此
代码设置为您的上一页一样,这将在新选项卡中打开您的页面,并且不会有可用的后退按钮。
Simply open your page in a new tab using javascript like this
set this code to your previous page and this will open your page in a new tab and there will be no back button available.