Share the post "How To Read QueryString Using Javascript In HTML"
HTML is a markup language so trying to look for ways to get values of query strings passed to the URL is not possible.
With Javascript however, it is. You can get the URL and its accompanying query string by using document.URL.
Now, to get the list of query strings and getting the value by key, we have to make our own custom function for this.
|
1 2 3 4 5 6 7 8 9 10 |
function getParams() { var params = []; var pairs = document.URL.split('?').pop().split('&'); for (var i = 0, p; i < pairs.length; i++) { p = pairs[i].split('='); params[p[0]] = p[1]; } return params; } |
To get the value of a query string key, see the sample code.
|
1 2 |
params = getParams(); console.log(params['key']); |