Web APIs: History.pushState()
12 February 2023 (Updated 12 February 2023)
On this page
In a nutshell
Creates a new entry in the browser’s session history.
If you want to replace instead of create a new entry, use the History.replaceState()
method instead,
Syntax:
history.pushState(state, unused, url)
Example:
const url = new URL(window.location);
url.searchParams.set('foo', 'bar');
window.history.pushState({}, '', url);
Parameters:
state
: Any serializable JavaScript object to be associated with the new history entry. (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.
Other notes
pushState
never triggers ahashchange
event, even if the new URL differs from the old URL only in the hash.
Sources
Tagged:
Web APIs
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment