Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

history.replaceState still adds entries to the "Browsing History"

Tags:

Specifically, calling the following snippet of code:

history.replaceState(undefined, undefined, "#" + value) 

will correctly not affect the back button behavior of the current page, but will add an entry to the "browsing history" page, which I don’t want. Pictured below is Chrome’s History page, but this also happens in Firefox.

Is there some way to replace the current URL without adding an entry to the user’s browsing history?

I’m inquiring about the standalone Browser History page, not the actual page navigation history that the Back button uses.

Chrome Browser History

like image 730
Vincent Woo Avatar asked Nov 07 '14 02:11

Vincent Woo


People also ask

What does Window history replaceState do?

The History. replaceState() method modifies the current history entry, replacing it with the state object and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.

What is the difference between pushState and replaceState?

The big difference is, that while pushState will create a new entry in the browser's history, replaceState will only replace the current state. As a side effect of this, using the replaceState method will change the URL in the address bar, without creating a new history entry.


1 Answers

I can't find any W3C spec on the global history, but even the session history is left unspecified to what the expected behavior is.

In practice, this has been an open bug for over 8 years with most of the browsers choosing to implement global history this way. In short, there probably isn't a workaround other than not calling pushState/replaceState.

like image 178
AnilRedshift Avatar answered Oct 20 '22 13:10

AnilRedshift