Created
April 29, 2013 08:42
-
-
Save hengkiardo/5480423 to your computer and use it in GitHub Desktop.
Read URL GET variables with Javascript
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
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