WindowEventHandlers.onhashchange
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julho de 2015.
O evento hashchange é disparado quando a hash da window muda. (ver location.hash).
Sintaxe
js
window.onhashchange = funcRef; ou:
html
<body onhashchange="funcRef();"></body> ou:
js
window.addEventListener("hashchange", funcRef, false); Parâmetros
funcRef-
Referência a uma função
Exemplo
js
if ("onhashchange" in window) { alert("O browser têm suporte ao evento hashchange!"); } function locationHashChanged() { if (location.hash === "#algointeressante") { algoInteressante(); } } window.onhashchange = locationHashChanged; O evento hashchange
O evento hashchange disparado possui os seguintes campos
| Campo | Tipo | Descrição |
|---|---|---|
newURL | DOMString | A nova URL para a qual a janela está navegando. |
oldURL | DOMString | A antiga URL da qual a janela veio. |
Especificações
| Specification |
|---|
| HTML> # event-hashchange> |
| HTML> # handler-window-onhashchange> |