History: 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.
Thestate read-only property of theHistory interfacereturns a value representing the state at the top of the history stack. This isa way to look at the state without having to wait for apopstate event.
In this article
Value
The state at the top of the history stack. The value isnull until thepushState() orreplaceState() method is used.
Examples
The code below logs the value ofhistory.state before using thepushState() method to push a value to the history.The next line logs the value to the console again, showing thathistory.state now has a value.
js
// Should be null because we haven't modified the history stack yetconsole.log("History.state before pushState: ", history.state);// Now push something on the stackhistory.pushState({ name: "Example" }, "pushState example", "page3.html");// Now state has a value.console.log("History.state after pushState: ", history.state);Specifications
| Specification |
|---|
| HTML> # dom-history-state-dev> |