The state
read-only property of the PopStateEvent
interface represents the state stored when the event was created.
Practically it is a value provided by the call to history.pushState()
or history.replaceState()
The state
read-only property of the PopStateEvent
interface represents the state stored when the event was created.
Practically it is a value provided by the call to history.pushState()
or history.replaceState()
An object, or null
.
The code below logs the value of state
when using the pushState()
method to push a value to the history.
js
// Log the state of
addEventListener("popstate", (event) => {
console.log("State received: ", event.state);
});
// Now push something on the stack
history.pushState({ name: "Example" }, "pushState example", "page1.html");
history.pushState(
{ name: "Another example" },
"pushState example",
"page1.html",
);
This will log:
State received: { name: "Example" }
State received: { name: "Another example" }
Specification |
---|
HTML Standard # dom-popstateevent-state-dev |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
state |
4 | 12 | 4 | 10 | ≤12.1 | 6 | 4.4 | 18 | 4 | ≤12.1 | 6 | 1.0 |
PopStateEvent()
constructorHistory.state
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PopStateEvent/state