Categories
JavaScript Answers

How to get hash parameters from request URL with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *