Web APIs: History.replaceState()
12 February 2023 (Updated 12 February 2023)
On this page
In a nutshell
History.replaceState() method modifies the current history entry, replacing it with the state object and URL passed as the method parameters. It’s useful when you want to replace the current URL or state in response to a user action (e.g., reflect the user’s input in a search box in a
?q=foobar query param).
If you want to create instead of replace a new entry in the session history, use the History.pushState() method instead.
replaceState(state, unused) replaceState(state, unused, url)
null. (Firefox has max size limit of 16MB).
unused: A parameter that exists only for historical reasons. Pass an empty string.
url(Optional): The new history entry’s URL. The new URL must be of the same origin as the current URL. Defaults to the document’s current URL.
Tagged: Web APIs