Created
May 13, 2011 07:24
-
-
Save alvinsj/970135 to your computer and use it in GitHub Desktop.
Get url parameters with javascript
This file contains hidden or 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
// 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