.gif)
Raised when there are changes to the portion of a
URL that follows the number sign (#).
Syntax
| Inline HTML | <ELEMENT onhashchange = "handler" ... >
| All platforms |
|---|
| Event property | object.onhashchange = handler | JScript only |
|---|
| object.onhashchange = GetRef("handler") | Visual Basic Scripting Edition (VBScript) 5.0 or later only |
| Named script |
<SCRIPT FOR =
object EVENT =
onhashchange>
| Internet Explorer only |
|---|
Event Information
| Bubbles | Yes |
|---|
| Cancels | Yes |
|---|
| To invoke | -
Set the
location.hash
(bookmark) property.
-
Navigate to the same page with a different bookmark.
|
|---|
| Default action |
N/A |
|---|
Event Object Properties
Although event handlers in the DHTML Object Model do not receive parameters directly, a handler can query the event object for the following event properties.
Available Properties
| cancelBubble |
Sets or retrieves whether the current event should bubble up the hierarchy of event handlers. |
|---|
| type |
Sets or retrieves the event name from the event object. |
|---|
Remarks
In Asynchronous JavaScript and XML (AJAX) applications, client requests
that do not trigger traditional page navigation
should update the
hash
property. This lets the Back button
function more predictably.
The URL fragment (bookmark) can be set by script.
The value is appended to the displayed URL,
and the navigation is saved in the browser history.
Internet Explorer 8. The browser's Back and Forward buttons do not generate onhashchange events for frames or iframes; instead, the frame is refreshed each time. Web pages hosted in frames or iframes should use their onload handler or equivalent to read the current URL hash information from the location.hash property and set their states accordingly.
When first navigating to a page that contains a hash identifier in the URL, an onhashchange event is not fired. It is expected that the freshly loaded page can inspect the value of the location.hash property to extract the current hash value. After this first page loads, setting the hash property will fire the onhashchange event as expected. This behavior avoids any negative impact on Web page load performance by removing a possible redundant event.
Example
Attaching an event handler to a new onhashchange event enables the page to detect when the hash has changed and an AJAX navigation has occurred. See Introducing AJAX Navigations for a more robust example.
<body onhashchange="HashChangeHandler();">
...
</body>
Standards Information
There is no public standard that applies to this event.
Applies To
See Also
Introducing AJAX Navigations