Javascript – jquery get querystring from URL – Stack Overflow

coke diet soundcloud

jquery get querystring from URL [duplicate]

I have the following URL:

What I need is to get the value of location from the URL into a variable and then use it in a jQuery code:

Does anyone know how to grab that value using JavaScript or jQuery?

marked as duplicate by Wesley Murch, Bill the Lizard Dec 5 ’12 at 20:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5 Answers 5

This is what you need 🙂

The following code will return a JavaScript Object containing the URL parameters:

For example, if you have the URL:

This code will return:

To retrieve the entire querystring from the current URL, beginning with the ? character, you can use

In regards to retrieving specific querystring parameters, while although classes like URLSearchParams and URL exist, they aren’t supported by Internet Explorer at this time, and should probably be avoided. Instead, you can try something like this:

Leave a Reply

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