PopStateEvent: state プロパティ
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
state は PopStateEvent インターフェイスの読み取り専用プロパティで、このイベントが生成されたときに格納された状態を表します。
実質的には、 history.pushState() または history.replaceState() の呼び 出しによって指定された値です。
値
オブジェクト、または null です。
例
以下のコードでは、 pushState() メソッドを使って値を履歴にプッシュしたときの state の値を記録しています。
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",
);
次のようにログ出力します。
State received: { name: "Example" }
State received: { name: "Another example" }
仕様書
| 仕様書 |
|---|
| HTML> # dom-popstateevent-state-dev> |
ブラウザーの互換性
関連情報
PopStateEvent()コンストラクターHistory.state