Window: hashchange event

The hashchange event is fired when the fragment identifier of the URL has changed (the part of the URL beginning with and following the # symbol).

Bubbles Yes
Cancelable No
Interface HashChangeEvent
Event handler onhashchange

Examples

You can use the hashchange event in an addEventListener method:

window.addEventListener('hashchange', function() {
  console.log('The hash has changed!')
}, false);

Or use the onhashchange event handler property:

function locationHashChanged() { 
  if (location.hash === '#cool-feature') { 
    console.log("You're visiting a cool feature!"); 
  } 
} 

window.onhashchange = locationHashChanged;

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'hashchange' in that specification.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
hashchange eventChrome Full support 5Edge Full support YesFirefox Full support 3.6IE Full support 8Opera Full support 10.6Safari Full support 5WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 4Opera Android Full support 11Safari iOS Full support 5Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

See also