How to get the value from the GET parameters?




I have a URL with some GET parameters as follows:



```
www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5 

```

I need to get the whole value of `c`. I tried to read the URL, but I got only `m2`. How do I do this using JavaScript?
JavaScript *itself* has nothing built in for handling query string parameters. 


Code running in a (modern) browser you can use the [`URL` object](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) (which is part of the APIs provided by browsers to JS):





```
var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
```









For older browsers (including Internet Explorer), you can use [this polyfill](https://github.com/ungap/url-search-params) or the code from the original version of this answer that predates `URL`:


You could access `location.search`, which would give you from the `?` character on to the end of the URL or the start of the fragment identifier (#foo), whichever comes first.


Then you can parse it with this:





```
function parse_query_string(query) {
  var vars = query.split("&");
  var query_string = {};
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    var key = decodeURIComponent(pair[0]);
    var value = decodeURIComponent(pair[1]);
    // If first entry with this name
    if (typeof query_string[key]  "undefined") {
      query_string[key] = decodeURIComponent(value);
      // If second entry with this name
    } else if (typeof query_string[key]  "string") {
      var arr = [query_string[key], decodeURIComponent(value)];
      query_string[key] = arr;
      // If third or later entry with this name
    } else {
      query_string[key].push(decodeURIComponent(value));
    }
  }
  return query_string;
}

var query_string = "a=1&b=3&c=m2-m3-m4-m5";
var parsed_qs = parse_query_string(query_string);
console.log(parsed_qs.c);
```




You can get the query string from the URL of the current page with:



```
var query = window.location.search.substring(1);
var qs = parse_query_string(query);

```
for this, just use an if function. see https://macmost.com/learn-how-to-use-the-if-function-in-numbers.html so something like this in a2: if(isblank(b2),c2,b2) the condition is to check if b2 is blank. if it is, get the value of c2. if it isn’t blank, then get the value of b2. You will want to look at the httpwebrequest class and its methods. You can feed it a URL and get back the source (page) to do with as you will. The MSDN articles that come up of you google httpwebrequest will help you. For a long time HtmlAgilityPack [didn't had the ability to directly query an attribute value](http://htmlagilitypack.codeplex.com/Thread/View.aspx?ThreadId=1720). You had to loop over the list of meta nodes. Here's one way - 



```
var doc = new HtmlDocument();
doc.LoadHtml(htmlString);

var list = doc.DocumentNode.SelectNodes("//meta"); 
foreach (var node in list)
{
    string content = node.GetAttributeValue("content", "");
}

```

But looks like in there is an [experimental xpath release](http://htmlagilitypack.codeplex.com/releases/view/46681) that will let you do that. 



```
doc.Document.SelectNodes("//meta/@content") 

```

will return a list of HtmlAttribute objects. hi chris, 
if you use relations api, you may set properties field in your query. in this field you should set the names of the properties which values must be retrieved from the server. the argument should be a string in the following format: "propertyname1, propertyname2, , , propertynamen" , wher… use promise.allsettled(). the following code works, it's simply going to skip over the rejected promise:
```javascript
function getwikiprofiles(data) {
 const profiles = data.people.map(person => {
 return getjson(wikiurl + person.name);
 });
 return promise.allsettled(profiles);
}
function generatehtml(data) {
 //console.log(data);
 data.foreach(person => {
 if (person.status  'fulfilled') {
 person = person.value;
 const section = document.createelement('section');
 peoplelist.appendchild(section);
 section.innerhtml = 
 ![](%24%7bperson.thumbnail.source%7d)
${person.title}



${person.description}


${person.extract}


;
 }
 });
``` The problem is the response from the server, not your JavaScript. I ran the following code in the console on your page:



```
$.getJSON('data.json', function(data) { 
    console.log(data); 
});

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

The result looks like this:



  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

 ![enter image description here](https://fooobar.com//img/b0b4666ec951695a00da8c82eb85e737.jpg)


As you can see, there is only one property in the returned object ( `mesta`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

, an array with three elements).


You can confirm this by [visiting the file directly`data.json`
  




 (adsbygoogle = window.adsbygoogle || []).push({});](https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=) . i got it over the internet.

var args = array.prototype.slice.call(arguments); 1 a c d
2 a
3 c
4 b
5 c
i got a 100% Okay well if those query parameters really do represent arbitrary text a visitor enters into fields, then personally I would push them to separate Adobe Analytics variables instead of concatenate them, because there's no guarantee on how many characters they will be or what characters will be entered. 

I'm not sure I understand what you mean... is your site just using different query parameters for search terms, depending on the page or search widget used? So e.g. maybe you do a search and it pops k=[search term] but on search results page you do another search and it instead pops query=[new search term] ?  If so, then it sounds to me like you shouldn't concat them, but instead just look for either one and push to the variable.  

Or is it that a visitor can go to your site and search for something that results in both of those parameters showing up in the URL at the same time, with different values? 

I think I need clarification about how your site actually works vs. these two parameters. 




[View solution in original post](/t5/dynamic-tag-management-questions/internal-search-term-tracking/m-p/278167#M1141) If I understand the question, it's much easier than people are saying - if you want to let WebClient do all the nuts and bolts of the request (including the redirection), but then get the *actual* response URI at the end, you can subclass WebClient like this:



```
class MyWebClient : WebClient
{
    Uri _responseUri;

    public Uri ResponseUri
    {
        get { return _responseUri; }
    }

    protected override WebResponse GetWebResponse(WebRequest request)
    {
        WebResponse response = base.GetWebResponse(request);
        _responseUri = response.ResponseUri;
        return response;
    }
}

```

Just use MyWebClient everywhere you would have used WebClient. After you've made whatever WebClient call you needed to do, then you can just use ResponseUri to get the actual redirected URI. *You'd need to add a similar override for GetWebResponse(WebRequest request, IAsyncResult result) too, if you were using the async stuff.*