I know you can obtain an URL variable by calling getUrlVars()["id"], however is there a way to get all (an unknown number of) variables in the URL? For a few reasons I am only allowed to do this on client side.
-
1See the second answer (high-voted) stackoverflow.com/questions/647259/javascript-query-stringMichael Berkowski– Michael Berkowski2012-01-13 04:05:53 +00:00Commented Jan 13, 2012 at 4:05
-
Cheers Michael, location.search.substring(1) works great.Pupper– Pupper2012-01-13 04:38:28 +00:00Commented Jan 13, 2012 at 4:38
Add a comment
|
2 Answers
try this:
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars[hash[0]] = hash[1];
}
return vars;
}
var url_vars = getUrlVars();
for(var i in url_vars)
{
alert(i + " == " + url_vars[i]);
}
1 Comment
Pupper
Wow why didn't I just do getUrlVars()...now I feel like an idiot :(