PopStateEvent: state プロパティ

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.

statePopStateEvent インターフェイスの読み取り専用プロパティで、このイベントが生成されたときに格納された状態を表します。

実質的には、 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" }

仕様書

Specification
HTML
# dom-popstateevent-state-dev

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
state

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報