Skip to content

Instantly share code, notes, and snippets.

@nus
Created August 18, 2012 19:39
Show Gist options
  • Save nus/3389269 to your computer and use it in GitHub Desktop.
Save nus/3389269 to your computer and use it in GitHub Desktop.
JavaScriptでURLパラメータをパース
function parseURLParams() {
var params_str = location.search.slice(1);
if(params_str.length < 1) {
return '';
}
var items = {};
var items_str = params_str.split(/[&;]/);
for(var i = 0, l = items_str.length; i < l; i++) {
var p = items_str[i];
var item = p.split('=');
if(item.length == 2) {
var key = decodeURIComponent(item[0]);
var value = decodeURIComponent(item[1]);
items[key] = value;
}
}
return items;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment