Sometimes, we want to get hash parameters from request URL with JavaScript.
In this article, we’ll look at how to get hash parameters from request URL with JavaScript.
How to get hash parameters from request URL with JavaScript?
To get hash parameters from request URL with JavaScript, we can use the URL
instance’s hash
property.
For instance, we write:
const hash = new URL("http://www.example.com/abc#xyz").hash;
console.log(hash)
to create a new URL
instance from a URL string.
Then we get the hash value of the URL from the hash
property.
Therefore, hash
is '#xyz'
.
Conclusion
To get hash parameters from request URL with JavaScript, we can use the URL
instance’s hash
property.