Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.