PopStateEvent: state property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
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()
Value
An object, or null
.
Examples
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" }
Specifications
Specification |
---|
HTML # dom-popstateevent-state-dev |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
state |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
PopStateEvent()
constructorHistory.state