Home  >  Article  >  Web Front-end  >  通过location.replace禁止浏览器后退防止重复提交_javascript技巧

通过location.replace禁止浏览器后退防止重复提交_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:37:121236browse

在网页设计中,可能由于某种需求,需要禁止浏览器的后退按钮,特别是一些对用户操作比较严格的网站,如果用户重复提交事件,然后又后退,这样可能会对某些数据产生灾难性的问题。所以今天就向大家介绍一种通过location.replace禁止浏览器后退按钮的方法。

这种方法的原理是,用新页面的URL替换当前的历史纪录,这样浏览历史记录中就只有一个页面,后退按钮永远处于失效状态,用户也就无法进行后退了。具体的使用方法如下所示:

①比如现在我要做一个超链接,这个链接链到页面htmer.htm,代码如下:

②如果是使用按钮进行超链接,则同样链接到页面htmer.htm的代码如下:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn