i have an URL like the followin,
http://test.com/testing/test/12345
12345 is the id. I want to take this using query string. How to take this value in javascript?
getAll() : This is to get an array of all the values in the query string. forEach() : This is to iterate over the parameters of the query string. keys() : This is to iterate over the keys of the query string. values() : This is to iterate over the values of the query string.
A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters.
The short answer is yes Javascript can parse URL parameter values. You can do this by leveraging URL Parameters to: Pass values from one page to another using the Javascript Get Method. Pass custom values to Google Analytics using the Google Tag Manager URL Variable which works the same as using a Javascript function.
Query parameters are those funny strings in a URL after the question mark ( ? ). Here's an example of a URL with a query parameter: https://www.
try like this
http://test.com/testing/test/12345
var aarr = window.location.href.split('/');
//get last value
var id = aarr[aarr.length -1];
or just
var id = window.location.href.split('/').pop()
Use this :
document.location.href.split('/').pop()
Running it on this page yields : 22139563#22139563
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With