WindowEventHandlers.onhashchange
O evento hashchange é disparado quando a hash da window muda. (ver location.hash
).
Sintaxe
window.onhashchange = funcRef;
ou
<body onhashchange="funcRef();">
ou
window.addEventListener("hashchange", funcRef, false);
Parâmetros
funcRef
-
Referência a uma função
Exemplo
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
Especificação | Status | Comentário |
---|---|---|
HTML Living Standard The definition of 'GlobalEventHandlers' in that specification. |
Padrão em tempo real | |
HTML 5.1 The definition of 'GlobalEventHandlers' in that specification. |
Recomendação | |
HTML5 The definition of 'GlobalEventHandlers' in that specification. |
Recomendação |
Compatibilidade dos Browsers
BCD tables only load in the browser