Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onhashchange event

onhashchange event

Event Object Reference Event Object

Example

Execute JavaScript when the anchor part changes:

Try it »


Definition and Usage

The onhashchange event is triggered when the anchor part of the current URL (starting with '#') changes.

Example of an anchor part: suppose the current URL is
http://www.example.com/test.htm#part2 - the anchor part in this URL is #part2.

You can invoke the event in the following ways:


Browser support

The numbers in the table indicate the version number of the first browser to support the event.

Events
onhashchange 5.0  8.0 3.6 5.0 10.6

Syntax

In HTML:

<

element

onhashchange="

myScript

">

Try it

In JavaScript:

object

.onhashchange=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

object

.addEventListener("hashchange",

myScript

);

Try it

Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.


Technical Details

Does it support bubbling: Yes
Is it cancelable: No
Event type: Event
Supported HTML tags:

Event Object Reference Event Object