Languages
[Edit]
EN

JavaScript - get hash part from current URL

0 points
Created by:
Palus-Bear
1016

In this article, we would like to show you how to get the hash part from the current URL in JavaScript.

Quick solution:

or:

 

Practical examples

Edit

Example 1

Edit

In this example, we get the hash part from the current url using substring() method on location.hash property.

JavaScript - get hash part from current URL
JavaScript - get hash part from current URL

Example 2

Edit

In this example, we get the current URL using location.href property. Then we get the substring from the URL starting from the # character index.

JavaScript - get hash part from current URL
JavaScript - get hash part from current URL

References

Edit
  1. location.hash - Web APIs | MDN
  2. location.href - Web APIs | MDN
  3. String.prototype.substring() - JavaScript | MDN
  4. String.prototype.indexOf() - JavaScript | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join