sajad torkamani

In a nutshell

The 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.

Syntax:

replaceState(state, unused)
replaceState(state, unused, url)

Parameters:

  • state: Any serializable JavaScript object to be associated with the new history entry. This can be 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.

Sources

Tagged: Web APIs

Leave a comment

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