Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. Web API
  3. Window
  4. Window: hashchange イベント

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

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 2015年7月.

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

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp