onhashchange event
Examples
JavaScript is executed when the anchor portion of changes:
<Body onhashchange = "myFunction ()">
try it"
Definition and Usage
onhashchange event trigger (with '#' as the start number) is changed when the anchor portion of the current URL.
Examples of the anchor section: specify the current URL is
http://www.example.com/test.htm#part2 - this URL in the anchor part # part2.
You can use the following ways to call the event:
- By setting the Location object of location.hash or location.href modify anchor some properties.
- Use different bookmarks to navigate to the current page (using the "Back" or "forward" button)
- Click on the link to jump to a bookmark anchor
Browser Support
Figures in the table represent the first browser to support this version of events.
event | |||||
---|---|---|---|---|---|
onhashchange | 5.0 | 8.0 | 3.6 | 5.0 | 10.6 |
grammar
In HTML:
<Elementonhashchange = "myScript"> try
In JavaScript:
object .onhashchange = function () {myScript }; try
JavaScript, use the addEventListener () method:
object .addEventListener ( "hashchange", myScript ); try
Note: Internet Explorer 8 and earlier versions of IE do not support addEventListener () method.
technical details
Whether to support the bubble: | Yes |
---|---|
It can be canceled: | No |
Event Type: | Event |
Supported HTML tags: | <Body> |