Web APIs

History.pushState()

Try the free JavaScript compiler

Adds a session-history entry without a document load. Does not itself dispatch popstate.

Formal Syntax & Structure

javascript syntaxjavascript
history.pushState(state, unused, url?)

Parameters & Attributes

NameTypeDescription
stateanySerializable state.
unusedstringLegacy argument, normally empty.
urlstring | nullOptional rewritten URL.

Return Value

undefined

No return value.

Working Example

Example Snippetjavascript
(async () => {let calls=0;window.addEventListener("popstate",()=>calls++);history.pushState({page:3},"");console.log(history.state.page,calls);})()
JavaScript Reference