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?
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 (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);