Javatpoint Logo
Javatpoint Logo

JavaScript hashchange Event

The hashchange event works to identify th the URL changes starting with the hashtag. The hash (#) tag starts with the URL or follows the URL to change the one to another link.

Syntax

The following event uses in the html with the script tag. We can see the event with the function for changing the hash link.

Examples

The following examples show the event information after working hashchange event with different functionalities.

Example 1

The basic hash charge event work with the location.hash event using the javascript functionality. We can get the alert message when the hash link change from one URL to another.

Output

The data shows the output of the hashchange event function.

JavaScript hashchange Event

Example 2

The following example uses a hashchange event with the different hash URLs on one page. Here, we use the id and its reference for the hashchange event. The function used on the body tag to operate for every url change.

Output

The data shows the output of the hashchange event function.

JavaScript hashchange Event

Example 3

The following example uses a hashchange event with the different hash URLs on one page. We can see the current url and old url changes using a single page. We can get the hashchange event to know the changed url from the different hash.

Output

The data shows the output of the hashchange event function.

JavaScript hashchange Event

Example4

The following example uses the document hash location to change the values. We can see the url of the document with the click function.

Output

The data shows the output of the hashchange event function.

JavaScript hashchange Event

Example 5

The following example uses a hashchange event with the different hash URLs on one page. We can see the addEventListner method with the hashchange event. The event works with the function. The function displays output when the hash of the url change.

Output

The data shows the output of the hashchange event function.

JavaScript hashchange Event

Example 6

The basic hashchage event works with the window event using the javascript functionality. We can get the information after change url using the "window.onhashchange " function.

Output

The data shows the output of the hashchange event function.

JavaScript hashchange Event

Conclusion

The events work on multiple URLs and hash links on the same page. It helps to maintain and operate the track of the changes link.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA