/Web APIs

HashChangeEvent: HashChangeEvent() constructor

The HashChangeEvent() constructor creates a new HashChangeEvent object, that is used by the hashchange event fired at the window object when the fragment of the URL changes.

Note: A web developer doesn't typically need to call this constructor, as the browser creates these objects itself when firing hashchange events.


new HashChangeEvent(type, options)



A string with the name of the event. It is case-sensitive and browsers set it to hashchange.

options Optional

An object that, in addition to the properties defined in Event(), has the following properties:

oldURL Optional

A string containing the old URL. Its default value is the empty string ("").


A string containing the new URL. Its default value is the empty string ("").

Return value

A new HashChangeEvent object.


Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
HashChangeEvent 16 12 11 No 15 6 4.4 18 14 14 6 1.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.