javascript 是什么阻止后退按钮在某些网站上工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6229227/
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-10-25 19:59:31  来源:igfitidea点击:

What keeps the back button from working on some sites?

javascriptjquery

提问by dzilla

So we've all been to some annoying websites that disable the back button in your browser. This can be circumvented by quickly pressing the back button two or three times. My question is: what is exactly happening when the back button is disabled and 2.) why does clicking the button two or three times fix the problem? Dying for an answer, don't let me down, SO! :)

所以我们都去过一些烦人的网站,这些网站禁用了浏览器中的后退按钮。这可以通过快速按两次或三次后退按钮来规避。我的问题是:当后退按钮被禁用时到底发生了什么和 2.) 为什么点击按钮两次或三次可以解决问题?渴望得到答案,不要让我失望,所以!:)

回答by Skilldrick

It's redirection - you click a link to page awhich redirects to page b. When you click back you go back to page awhich instantly redirects you back to page b. If you click twice quickly then there isn't time to redirect.

它是重定向 - 您单击一个指向页面的链接,a该链接将重定向到 page b。当您单击返回时,您将返回页面a,该页面会立即将您重定向回页面b。如果您快速单击两次,则没有时间重定向。

I don't think your question has anything to do with Twitter. There's another back-button problem with JavaScript apps that don't do page reloads where changes to the page don't register as history events, so pressing back takes you back much further than you expected. But that's a completely unrelated issue.

我认为你的问题与 Twitter 无关。不重新加载页面的 JavaScript 应用程序还有另一个后退按钮问题,其中对页面的更改不会注册为历史事件,因此按后退会比您预期的更远。但这是一个完全不相关的问题。

回答by joshmax

I think you'll find a decent answer here (http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm) under Method Three: Frames Trap.

我想你会在这里找到一个不错的答案(http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm)在方法三:帧陷阱下

回答by Jishnu A P

In some sites they disable it by the following code.

在某些站点中,他们通过以下代码禁用它。

window.history.forward();

回答by Anthony Grist

More than likely they have an intermediate page with a redirect. Clicking the back button once simply returns you to that page, and you get redirected back to the page you intended to go back from. Clicking multiple times returns you to the intermediate page (on the first click), then the page before (on the second click), etc.

他们很可能有一个带有重定向的中间页面。单击后退按钮一次只会将您返回到该页面,然后您将被重定向回您打算返回的页面。单击多次返回中间页面(第一次单击时),然后返回之前的页面(第二次单击时),依此类推。

回答by SamT

If you've landed on a page with a meta redirect to another page, you will find that hitting the back button does not work because you hit back to go to the page that redirects you to the page you're already on. Typically Location headers don't cause you to be trapped like that, as the page that sends you away is not recorded in most browsers' history.

如果您登陆了一个带有元重定向到另一个页面的页面,您会发现点击后退按钮不起作用,因为您点击返回页面,该页面将您重定向到您已经在的页面。通常位置标头不会让您像那样被困,因为大多数浏览器的历史记录中不会记录将您送走的页面。

回答by haknick

The page where you're trying to go back to has a redirect so as soon as you click the back button you are redirected to the current page right away. By clicking a few times in quick succession the redirect does not have enough time to complete so you are able to jump to the page before that.

您尝试返回的页面有一个重定向,因此只要您单击后退按钮,您就会立即重定向到当前页面。通过快速连续单击几次,重定向没有足够的时间来完成,因此您可以在此之前跳转到页面。