--- title: WindowEventHandlers.onhashchange slug: Web/API/WindowEventHandlers/onhashchange translation_of: Web/API/WindowEventHandlers/onhashchange ---
O evento hashchange é disparado quando a hash da window muda. (ver {{domxref("Window.location", "location.hash")}}).
window.onhashchange = funcRef;
ou
<body onhashchange="funcRef();">
ou
window.addEventListener("hashchange", funcRef, false);
funcRef
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 disparado possui os seguintes campos
Campo | Tipo | Descrição |
newURL {{gecko_minversion_inline("6.0")}} |
DOMString |
A nova URL para a qual a janela está navegando. |
oldURL {{gecko_minversion_inline("6.0")}} |
DOMString |
A antiga URL da qual a janela veio. |
Especificação | Status | Comentário |
---|---|---|
{{SpecName('HTML WHATWG', '#windoweventhandlers', 'GlobalEventHandlers')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5.1', '#windoweventhandlers', 'GlobalEventHandlers')}} | {{Spec2('HTML5.1')}} | |
{{SpecName("HTML5 W3C", "#windoweventhandlers", "GlobalEventHandlers")}} | {{Spec2('HTML5 W3C')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suporte Básico | 5.0 | {{CompatGeckoDesktop("1.9.2")}} |
8.0 atributos |
10.6 | 5.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Suporte Básico | 2.2 | {{CompatGeckoMobile("1.9.2")}} | 9.0 | 11.0 | 5.0 |