--- title: WindowEventHandlers.onhashchange slug: Web/API/WindowEventHandlers/onhashchange translation_of: Web/API/WindowEventHandlers/onhashchange ---
Событие hashchange происходит когда изменяется hash (смотри {{domxref("Window.location", "location.hash")}}).
window.onhashchange = funcRef;
или
<body onhashchange="funcRef();">
или
window.addEventListener("hashchange", funcRef, false);
funcRef
if ("onhashchange" in window) { alert("The browser supports the hashchange event!"); } function locationHashChanged() { if (location.hash === "#somecoolfeature") { somecoolfeature(); } } window.onhashchange = locationHashChanged;
The dispatched hashchange
event has the following fields:
Field | Type | Description |
newURL {{gecko_minversion_inline("6.0")}} |
DOMString |
The new URL to which the window is navigating. |
oldURL {{gecko_minversion_inline("6.0")}} |
DOMString |
The previous URL from which the window was navigated. |
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', '#windoweventhandlers', 'GlobalEventHandlers')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5.1', '#windoweventhandlers', 'GlobalEventHandlers')}} | {{Spec2('HTML5.1')}} | |
{{SpecName("HTML5 W3C", "#windoweventhandlers", "GlobalEventHandlers")}} | {{Spec2('HTML5 W3C')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 5.0 | {{CompatGeckoDesktop("1.9.2")}} |
8.0
|
10.6 | 5.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 2.2 | {{CompatGeckoMobile("1.9.2")}} | 9.0 | 11.0 | 5.0 |