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 July 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 |
Compatibilidade com navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
hashchange event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.