Skip to content

Instantly share code, notes, and snippets.

@ikennaokpala
Created March 12, 2011 04:00
Show Gist options
  • Save ikennaokpala/867015 to your computer and use it in GitHub Desktop.
Save ikennaokpala/867015 to your computer and use it in GitHub Desktop.
Get url parameter values
// http://localhost:8080/index?id=546&name=kengimel
var id = myVars.getUrlVars()["id"];
var name = myVars.getUrlVars()["name"];
console.log("ID is currently this value: "+id);
console.log("Name is currently this value: "+name);
var myVars= {
getUrlVars: function() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment