Revision: 24222
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 23, 2010 19:32 by tsunammis
Initial Code
/*
* Allow to get into associative array, the GET variable of one URL
*
* USING:
* To get all the variable of one URL
* var a = getUrlVars('http://domaine.tld/index.php?me=beauGosse&Robert=Moche')["me"];
* return {"me" : "beauGosse", "Robert" : "Moche"}
*
* To get a value of first parameter you would do this:
* var f = getUrlVars('http://domaine.tld/index.php?me=beauGosse&Robert=Moche')["me"];
* return beauGosse
*
* To get the second parameter
* var s = getUrlVars('http://stan.com/index.php?me=beauGosse&Robert=Moche')["Robert"];
* return Moche
*
* INSPIRATION:
* http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
*/
function getVarsGet(url)
{
var vars = {}, hash;
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars[hash[0]] = hash[1];
}
return vars;
}
Initial URL
Initial Description
Initial Title
get the GET variable of one URL into variable
Initial Tags
url
Initial Language
JavaScript