值
历史堆栈顶部的状态。在使用 pushState() 或 replaceState() 方法之前,该值始终为 null。
示例
下面的代码在调用 pushState() 方法将值推入历史记录之前,记录了 history.state 的值。下一行代码再次将值记录到控制台,显示 history.state 现在具有了一个值。
js
// Should be null because we haven't modified the history stack yet
console.log("History.state before pushState: ", history.state);
// Now push something on the stack
history.pushState({ name: "Example" }, "pushState example", "page3.html");
// Now state has a value.
console.log("History.state after pushState: ", history.state);
规范
| 规范 |
|---|
| HTML # dom-history-state-dev |
浏览器兼容性
加载中…