Skip to content

Instantly share code, notes, and snippets.

@alvinsj
Created May 13, 2011 07:24
Show Gist options
  • Save alvinsj/970135 to your computer and use it in GitHub Desktop.
Save alvinsj/970135 to your computer and use it in GitHub Desktop.
Get url parameters with javascript
// get url parameters with javascript (e.g.: sample.html?udid=123&device=iphone)
function getURLParams() {
var params= new Object();
var query = window.location.search.substring(1);
var pairs = query.split('&');
for (var i=0; i<pairs.length; i++) {
var pos = pairs[i].indexOf('=');
if (pos > 0) {
var key = pairs[i].substring(0,pos);
var val = pairs[i].substring(pos+1);
params[key] = val;
}
}
return params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment