HashChangeEvent - Web APIs | MDN

Constructor

HashChangeEvent()

Creates a new HashChangeEvent object.

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.

Examples

Basic example

js

function locationHashChanged() {
  if (location.hash === "#some-cool-feature") {
    someCoolFeature();
  }
}

window.addEventListener("hashchange", locationHashChanged);

Specifications

Specification
HTML
# the-hashchangeevent-interface

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.