值
歷史堆疊頂部的狀態。在使用 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 |
瀏覽器相容性
載入中…