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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With