web api interface
HashChangeEvent
The HashChangeEvent interface represents events that fire when the fragment identifier of the URL has changed.
The fragment identifier is the part of the URL that follows (and includes) the # symbol.
Constructor
HashChangeEvent()- : Creates a new
HashChangeEventobject.
- : Creates a new
Instance properties
This interface also inherits the properties of its parent, Event.
newURLRead only- : The new URL to which the window is navigating.
oldURLRead only- : The previous URL from which the window was navigated.
Instance methods
This interface has no methods of its own, but inherits the methods of its parent, Event.
Examples
Basic example
function locationHashChanged() {
if (location.hash === "#some-cool-feature") {
someCoolFeature();
}
}
window.addEventListener("hashchange", locationHashChanged);
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.