WindowEventHandlers.onhashchange
Событие hashchange происходит когда изменяется hash (смотри 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 hashchange event
The dispatched hashchange
event has the following fields:
Field | Type | Description |
newURL |
DOMString |
The new URL to which the window is navigating. |
oldURL |
DOMString |
The previous URL from which the window was navigated. |
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard Определение 'GlobalEventHandlers' в этой спецификации. |
Живой стандарт | |
HTML 5.1 Определение 'GlobalEventHandlers' в этой спецификации. |
Рекомендация | |
HTML5 Определение 'GlobalEventHandlers' в этой спецификации. |
Рекомендация |
Поддержка браузерами
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 5.0 | 3.6 (1.9.2) |
8.0
|
10.6 | 5.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 2.2 | 1.0 (1.9.2) | 9.0 | 11.0 | 5.0 |