Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Created April 22, 2015 00:59
Show Gist options
  • Save RyoSugimoto/af0c46e9eb5e8547bbc8 to your computer and use it in GitHub Desktop.
Save RyoSugimoto/af0c46e9eb5e8547bbc8 to your computer and use it in GitHub Desktop.
クエリ文字列をオブジェクトに変換して返す。
var getQuery = function (url) {
if (typeof url !== 'string') {
url = window.location.href;
}
var queries = url.slice(url.indexOf('?') + 1).split('&'),
obj = {};
for (var i = queries.length; i--;) {
var query = queries[i].split('=');
obj[query[0]] = query[1];
}
return obj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment