/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * 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; }