javascript “window.history.forward(1);”不工作
我试图阻止后退按钮在我的 asp.net mvc 页面之一上工作。 我读过一些地方,如果我输入“window.history.forward(1);”在我的页面中,它将阻止后退按钮在给定页面上工作。 这就是我在我的页面中所做的:
<script type="text/javascript">
$(document).ready(function () {
window.history.forward(1);
});
</script>
它似乎不起作用。我是否使用了错误的方法或者这种方法是错误的?谢谢。
I'm trying to prevent the back button from working on one of my asp.net mvc pages.
I've read a couple of places that if i put "window.history.forward(1);" in my page it will prevent the back button from working on a given page.
This is what I did in my page:
<script type="text/javascript">
$(document).ready(function () {
window.history.forward(1);
});
</script>
It doesn't seem to be working. Am I using this incorrectly or is this approach wrong? thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我看到这个技巧的使用方法是在您不希望后退按钮起作用的页面之前的每个页面上放置
history.forward()
,然后每次用户点击后退时按钮会将它们转发回原来的位置。常见用途是防止其他人在完成操作后返回页面(通常以给定的线性顺序)。例如,有时这会用在银行网站的登录序列中。据我所知,没有办法真正禁用后退按钮。有时,人们通过在新窗口中打开页面来解决此问题,该窗口不会有之前页面的历史记录,因此无需返回。其他人只是在返回之前显示一条警告消息,通知用户他们可能会丢失未保存的数据(如果这是主要问题)。
也就是说,也许这会对您有所帮助: http://viralpatel.net/blogs /disable-back-button-browser-javascript/
The way I've seen this trick used is to put
history.forward()
on every page before the page where you don't want the back button to work, then every time the user hits the back button it forwards them back to where they were. The common use is to prevent others from returning to a page (usually in a given, linear sequence) once they have progressed. This is sometimes used in the sign-in sequence for banking websites, for example.As far as I know, there is no way to actually disable the back button. Sometimes people get around this by opening the page in a new window, which will not have a history of pages preceding it, and thus nothing to go back to. Others simply display a warning message before going back to inform a user that they may lose unsaved data, if that is the main concern.
That said, maybe this will help you: http://viralpatel.net/blogs/disable-back-button-browser-javascript/
或许:...
maybe:...
在您不希望后退按钮起作用的页面上使用。
window.history.forward(1);
Use on the page in which you don't want back button to work.
window.history.forward(1);
这对我有用...希望对您有帮助..
This is working for me... Hope it helpful for you..
您可以使用
You can use
并在html Body标签中写入以下代码。
试试这个,它对我有用。
And in html Body tag write the following code.
Try this, it worked for me.
不确定这是否相关,但我发现了它,可能值得一试:
Not sure if this is relevant but I found it and it might be worth a try:
该代码需要位于前面的页面以及您需要它运行的页面上
The code needs to be on the page infront as well as the page you require for it to work