hashchange
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.
Event HashChangeEvent
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 8 | 12 | 3.6 | 5 | 18 | 5 | |
| The HashChangeEvent() constructor creates a new HashChangeEvent object, that is used by the Window/hashchange_event event fired at the window object when the fragment of the URL changes. | 16 | 12 | 11 | 6 | 18 | 6 |
| The newURL read-only property of the HashChangeEvent interface returns the new URL to which the window is navigating. | 8 | 12 | 6 | 5.1 | 18 | 5 |
| The oldURL read-only property of the HashChangeEvent interface returns the previous URL from which the window was navigated. | 8 | 12 | 6 | 5.1 | 18 | 5 |
| 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). | 8 | 12 | 3.6 | 5 | 18 | 5 |
- This feature was removed in a later browser version (8)
- A regular `Event` object is fired, rather than a `HashChangeEvent` object.
Use cases
-
Using hashchange
The HashChangeEvent interface represents events that fire when the fragment identifier of the URL has changed.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.