Reputation: 21
I have URL adresses like this:
http:://www.mywebsite.com/myapp?brand=nameOfBrand&user=0123456&type=comm
I have to use that info to show the logo of 'nameOfBrand'.
So if I get brand=google
, the logo of Google will appear, if I get brand=Amazon
, the logo of Amazon appears, and so on...
Do you know how I can get this parameter?
Upvotes: 1
Views: 1907
Reputation: 12874
var url_string = "http://www.mywebsite.com/myapp?brand=nameOfBrand&user=0123456&type=comm"; //window.location.href
var url = new URL(url_string);
var brand = url.searchParams.get("brand");
console.log(brand);
You can use URL
to convert it and using searchParams.get
method to grab the particular value that you want.
For more information
Upvotes: 2