History: 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.
state
は History
インターフェイスの読み取り専用プロパティで、履歴スタックの一番上の状態を表す値を返します。これは popstate
イベントを待つことなく、状態を見ることができる方法です。
値
履歴スタックの一番上の状態です。この値は pushState()
または replaceState()
メソッドが使用されていない限り null
です。
例
以下のコードでは、 history.state
の値を pushState()
メソッドを使用して値を履歴にプッシュする前に、ログに記録しています。
次の行では、再びコンソールに値が記録され、 history.state
に値があることが分かります。
js
// まだ履歴スタックを変更していないため、 null になります
console.log("History.state before pushState: ", history.state);
// スタックに何かプッシュします
history.pushState({ name: "Example" }, "pushState example", "page3.html");
// 状態は値になりました。
console.log("History.state after pushState: ", history.state);
仕様書
Specification |
---|
HTML # dom-history-state-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
state |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.