如何使用JavaScript来禁用浏览器的背面按钮 [英] How to disable back button of browser using JavaScript

查看:87
本文介绍了如何使用JavaScript来禁用浏览器的背面按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用使用JavaScript在浏览器中后退按钮。任何一个可以帮助我该怎么做?

I want to disable the back buttons in the browser using JavaScript. Can any one help me how to do that?

推荐答案

在这里阅读几个选项来禁用后退按钮

但是:这个问题让我觉得你试图解决错误的问题。

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:


  1. 您可以获取事件当用户使用该按钮。 GWT,例如,保存在虚拟历史事件的应用程序的内部状态。因此,用户可以使用在实际应用像撤消返回按钮。

  1. 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.

为避免你的页面创造历史的事件。确保在标题栏永远不会改变的URL。保存在服务器上的所有更改。对于用户来说,网页/应用程序会感觉像一个页面。当他返回接下来的时间,恢复你的服务器从数据库的最后状态。

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来禁用浏览器的背面按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆