A question asked without possibly an end is how do I get variable from a URL. In all my searching I have found several very good ways to get A=aValue
from the url.
But my question is I need
?Company=FLHS&Device=Crosstown_PCC_01&A=aValue&A=secondAValue
I need an array of the two A's in the url and I need to know that aValue
was the first one and secondAValue
was the second
I have jquery Mobile.
Update
So this is what I have now
var urlParamDevice = getURLParameter('DeviceID');
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
);
The getURLParameter(name) needs to be a little more robust.
Update 2, 2014/03/07 Here is what I came up with from the suggested answer
function getQueryParams(name) {
qs = location.search;
var params = [];
var tokens;
var re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs))
{
if (decodeURIComponent(tokens[1]) == name)
params.push(decodeURIComponent(tokens[2]));
}
return params;
}