Window.onhashchange

  • Revision slug: DOM/window.onhashchange
  • Revision title: window.onhashchange
  • Revision id: 30961
  • Created:
  • Creator: Crash
  • Is current revision? No
  • Comment page created, 92 words added

Revision Content

The hashchange event gets fired when the URL hash (location.hash) is changes.

Syntax

window.onhashchange = funcRef;

Parameters

  • funcRef is a reference to a function.

Example

function locationHashChanged() {
    if (location.hash == "#somecoolfeature") {
        somecoolfeature();
    }
}

window.onchange = locationHashChanged;

See Also

  • Bug 385434 - Add support for HTML5 onhashchange (event for named anchor changes)
  • Bug 504837 - hashchange event should not be restricted to firing only when the document's ready state is "complete"
  • Bug 504220 - document.body and window should contain onhashchange attribute

Specification

Revision Source

<p>The <strong>hashchange</strong> event gets fired when the URL hash (<em>location.hash</em>) is changes.</p>
<h3 class="editable"><span>Syntax </span></h3>
<pre>window.onhashchange = funcRef;
</pre>
<h3 class="editable"><span>Parameters </span></h3>
<ul> <li><code>funcRef</code> is a reference to a function.</li>
</ul>
<h3 class="editable"><span>Example</span></h3>
<pre>function locationHashChanged() {
    if (location.hash == "#somecoolfeature") {
        somecoolfeature();
    }
}

window.onchange = locationHashChanged;
</pre>
<h3 class="editable"><span>See Also</span></h3>
<ul> <li><a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=385434" title="https://bugzilla.mozilla.org/show_bug.cgi?id=385434">Bug 385434</a> - Add support for HTML5 onhashchange (event for named anchor changes)</li> <li><a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=504837" title="https://bugzilla.mozilla.org/show_bug.cgi?id=504837">Bug 504837</a> - <span class="bz_default_hidden" id="summary_alias_container" style="display: inline;"><span id="short_desc_nonedit_display">hashchange event should not be restricted to firing only when the document's ready state is "complete"</span></span></li> <li><a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=504220" title="https://bugzilla.mozilla.org/show_bug.cgi?id=504220">Bug 504220</a> - <span class="bz_default_hidden" id="summary_alias_container" style="display: inline;"><span id="short_desc_nonedit_display">document.body and window should contain onhashchange attribute</span></span></li>
</ul>
<h3 class="editable"><span>Specification</span></h3>
<ul> <li><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/#handler-window-onhashchange" title="http://www.whatwg.org/specs/web-apps/current-work/#handler-window-onhashchange"><span>http://www.whatwg.org/specs/web-apps/current-work/#handler-window-onhashchange</span></a></li>
</ul>
Revert to this revision