sajad torkamani

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 a hashchange event, even if the new URL differs from the old URL only in the hash.

Sources

Tagged: Web APIs

Leave a comment

Your email address will not be published. Required fields are marked *