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

Поддержка браузерами

{{Compat}}