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

Instance properties

This interface also inherits the properties of its parent, Event.

HashChangeEvent.newURL Read only

The new URL to which the window is navigating.

HashChangeEvent.oldURL Read 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.


Basic example

function locationHashChanged() {
  if (location.hash === '#somecoolfeature') {

window.addEventListener('hashchange', locationHashChanged);


HTML Standard
# the-hashchangeevent-interface

Browser compatibility

BCD tables only load in the browser