What keeps the back button from working on some sites?
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开发者_StackOverflow中文版. 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! :)
It's redirection - you click a link to page a
which redirects to page b
. When you click back you go back to page a
which instantly redirects you back to page b
. If you click twice quickly then there isn't time to redirect.
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.
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.
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.
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.
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.
In some sites they disable it by the following code.
window.history.forward();
精彩评论