Skip to content

Instantly share code, notes, and snippets.

@hengkiardo
Created April 29, 2013 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hengkiardo/5480423 to your computer and use it in GitHub Desktop.
Save hengkiardo/5480423 to your computer and use it in GitHub Desktop.
Read URL GET variables with Javascript
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
/// http://hengkiardo.com/index.php?id=123&page=home
var first = getUrlVars()["id"];
var second = getUrlVars()["page"];
console.log(first);
// 123
console.log(second);
// home
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment