Javascript 禁用浏览器“后退”按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3611446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:25:50  来源:igfitidea点击:

Disable browser "back" button

javascriptjqueryasp.net-mvc

提问by SRA

Possible Duplicate:
Disable browser's back button

可能的重复:
禁用浏览器的后退按钮

How can I disable a browsers back button, in an asp.net mvc project. Can I use java script for this ? or is there any other ways to do this ?

如何在 asp.net mvc 项目中禁用浏览器后退按钮。我可以为此使用 java 脚本吗?或者有没有其他方法可以做到这一点?

回答by Ta01

This has often been discussed on countless threads, the most exhaustive article is hereand why it always will not work.

这经常在无数线程上讨论,最详尽的文章在这里以及为什么它总是行不通。

回答by Chet

A website should not try to cripple the browser, but instead should work inside the browser-page system of the web. There are good reason for not wanting the user to click back (re-POSTing data, especially financial transactions and the like), but rather than forcing them not to, your website should handle these gracefully. Using a good framework like .NET leaves you a lot of great options for keeping your site stateful even amid the stateless web. Write your code to fit the browser, don't make the browser fit your code (like the ridiculous no-right-click javascripts of yesteryear).

一个网站不应该试图削弱浏览器,而应该在网络的浏览器页面系统内工作。有充分的理由不希望用户点击返回(重新发布数据,尤其是金融交易等),但与其强迫他们不要点击,您的网站应该优雅地处理这些。使用像 .NET 这样的优秀框架可以为您提供许多很好的选择,即使在无状态网络中也能保持您的站点有状态。编写适合浏览器的代码,不要让浏览器适合您的代码(就像过去荒谬的非右键单击 javascripts)。

That said, thankfully there is no way to do this, and even if there were, it could always be disabled on the client side.

也就是说,幸运的是没有办法做到这一点,即使有,它也总是可以在客户端被禁用。

回答by Anthony Greco

I would have to assume it is impossible. That would be a big security issue on most browsers. I don't even remember in IE4 when the most extreme things were allows, you being able to do it.

我不得不假设这是不可能的。对于大多数浏览器来说,这将是一个很大的安全问题。我什至不记得在 IE4 中什么时候允许最极端的事情,你能够做到。

回答by tehsis

I don't think that you can disable the back button, althought there are some "techniques" like those described in this site: http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm

我不认为你可以禁用后退按钮,虽然有一些“技术”,比如本网站中描述的那些:http: //www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the -Back-Button.htm

回答by dvanaria

It is not possible to the disable the BACK button of the browser, but if you don't want the user to go back to a previous page then you can add this javascript function to your page:

无法禁用浏览器的后退按钮,但如果您不希望用户返回上一页,则可以将此 javascript 函数添加到您的页面:

<script language="javascript">
function DisableBackButton()
{
history.forward();
}
</script>
And call this function in body only..
Like

<form id="form1" runat="server">
<script language="javascript">DisableBackButton();</script>
---your page design----------
</form>