Window: hashchange イベント
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.
hashchange
イベントは、 URL のフラグメント識別子 (URL の #
記号で始まり続く部分) が変化したときに発生します。
バブリング | あり |
---|---|
キャンセル | 不可 |
インターフェイス | HashChangeEvent |
イベントハンドラープロパティ |
onhashchange
|
例
hashchange
イベントは addEventListener
メソッドの中で使用することができます。
js
window.addEventListener(
"hashchange",
function () {
console.log("The hash has changed!");
},
false,
);
または onhashchange
イベントハンドラープロパティを使用して、
js
function locationHashChanged() {
if (location.hash === "#cool-feature") {
console.log("You're visiting a cool feature!");
}
}
window.onhashchange = locationHashChanged;
仕様書
Specification |
---|
HTML # event-hashchange |
HTML # handler-window-onhashchange |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
hashchange event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
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.