I have URL like this:
http://localhost/PMApp/temp.htm?ProjectID=462
What I need to do is to get the details after the ? sign (query string) – that is ProjectID=462. How can I get that using JavaScript?
What I’ve done so far is this:
var url = window.location.toString();
url.match(?);
I don’t know what to do next.
Have a look at the MDN article about
window.location.The QueryString is available in
window.location.search.If you want a more convenient interface to work with, you can use the
searchParamsproperty of the URL interface, which returns a URLSearchParams object. The returned object has a number of convenient methods, including a get-method. So the equivalent of the above example would be:The URLSearchParams interface can also be used to parse strings in a querystring format, and turn them into a handy URLSearchParams object.
The URLSearchParams interface is now widely adopted in browsers (95%+ according to Can I Use), but if you do need to support legacy browsers as well, you can use a polyfill.