How do some websites prevent us from going back to the previous page?

191 views

Do you know these shady websites that don’t allow you to go back, only after spamming the previous page button, or in some cases, the only option is to close the tab. How can web devs disable basic browser functions like that?

In: 4

4 Answers

Anonymous 0 Comments

Ah the thing is for certain types of websites that update dynamically with like JavaScript, instead of clicking a link and reloading the entire page, it’s important to be able to tell the browser directly that pressing the back button goes to a specific state. That way after clicking a few menus, pressing back takes you to before you clicked a menu item and not away from the website.

Spam websites just highjack that same mechanism to flood the back button entries. So you click back and it reloads the current spam, and floods some more fake entries into the history.

Anonymous 0 Comments

I think what you described is done by making your browser load the page multiple times consecutively, so that if you go back one page, the last page that was loaded was also the page you’re currently on.

I don’t know about other browsers, but in Firefox you can hold the “previous page” button and it shows you the last 14 pages you visited. Many times it showed me that the last 10 pages or so were the page I’m currently on, but the page before that was the page where I originally came from and I was able to get back.

Anonymous 0 Comments

There’s a mechanism that lets the developers change the URL without having to reload the whole page.

Just look at Reddit when you open a post. It opens it in a sort of popup that you can close. The URL changes but the page doesn’t reload.

You can also click the browser’s back button to go back to the previous page. This is because the browser knows which pages you visited in a given tab, we call this history.

This mechanism can be abused by changing the url many times very quickly, flooding the browser’s history. So when you press back, you’re just iterating over the same page with a slightly different URL.

Anonymous 0 Comments

The ones that you can bypass by spamming the back button are more primitive. Instead of taking you to the page itself, it takes you to a page that automatically redirects you to the actual page (sometimes with a few layers of this). That way clicking back just sends you to the redirect and then back to where you were. This is fairly trivially defeated by spamming back a few times so it goes back before the browser processes the redirect request.