HashChangeEvent
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.
HashChangeEvent
インターフェイスは、URL のフラグメント識別子が変更されたときに発生するイベントを表します。
フラグメント識別子は URL の一部で、#
記号からそれに続く部分です。
コンストラクター
HashChangeEvent()
-
新しい
HashChangeEvent
オブジェクトを生成します。
インスタンスプロパティ
このインターフェイスには、親である Event
から継承したプロパティもあります。
HashChangeEvent.newURL
読取専用-
ウィンドウが移動しようとしている新しい URL。
HashChangeEvent.oldURL
読取専用-
ウィンドウがいた直前の URL。
インスタンスメソッド
このインターフェイスには自身のメソッドがありませんが、親である Event
から継承したメソッドがあります。
例
基本的な例
js
function locationHashChanged() {
if (location.hash === "#somecoolfeature") {
somecoolfeature();
}
}
window.addEventListener("hashchange", locationHashChanged);
仕様書
Specification |
---|
HTML # the-hashchangeevent-interface |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
HashChangeEvent | ||||||||||||
HashChangeEvent() constructor | ||||||||||||
newURL | ||||||||||||
oldURL |
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.