Created
March 12, 2011 04:00
-
-
Save ikennaokpala/867015 to your computer and use it in GitHub Desktop.
Get url parameter values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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