From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../ja/web/api/window/hashchange_event/index.html | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 files/ja/web/api/window/hashchange_event/index.html (limited to 'files/ja/web/api/window/hashchange_event/index.html') diff --git a/files/ja/web/api/window/hashchange_event/index.html b/files/ja/web/api/window/hashchange_event/index.html new file mode 100644 index 0000000000..5af90df187 --- /dev/null +++ b/files/ja/web/api/window/hashchange_event/index.html @@ -0,0 +1,86 @@ +--- +title: 'Window: hashchange イベント' +slug: Web/API/Window/hashchange_event +tags: + - API + - Event + - HTML DOM + - Reference + - Window + - イベント +translation_of: Web/API/Window/hashchange_event +--- +
{{APIRef}}
+ +

hashchange イベントは、 URL のフラグメント識別子 (URL の # 記号で始まり続く部分) が変化したときに発生します。

+ + + + + + + + + + + + + + + + + + + + +
バブリングあり
キャンセル不可
インターフェイス{{domxref("HashChangeEvent")}}
イベントハンドラープロパティ{{domxref("WindowEventHandlers/onhashchange", "onhashchange")}}
+ +

+ +

hashchange イベントは {{domxref("EventTarget/addEventListener", "addEventListener")}} メソッドの中で使用することができます。

+ +
window.addEventListener('hashchange', function() {
+  console.log('The hash has changed!')
+}, false);
+ +

または onhashchange イベントハンドラープロパティを使用して、

+ +
function locationHashChanged() {
+  if (location.hash === '#cool-feature') {
+    console.log("You're visiting a cool feature!");
+  }
+}
+
+window.onhashchange = locationHashChanged;
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('HTML WHATWG', 'indices.html#event-hashchange', 'hashchange')}}{{Spec2('HTML WHATWG')}}Initial definition
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.Window.hashchange_event")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf