Skip to content

Instantly share code, notes, and snippets.

@nabettu
Created May 27, 2015 04:14
Show Gist options
  • Save nabettu/0eafdfe1c7d2c22b2d9a to your computer and use it in GitHub Desktop.
Save nabettu/0eafdfe1c7d2c22b2d9a to your computer and use it in GitHub Desktop.
GET的にURLに入っている内容を取得する。
function getQueryString() {
var result = {};
if (1 < window.location.search.length) {
var query = window.location.search.substring(1);
var parameters = query.split('&');
for (var i = 0; i < parameters.length; i++) {
var element = parameters[i].split('=');
var paramName = decodeURIComponent(element[0]);
var paramValue = decodeURIComponent(element[1]);
result[paramName] = paramValue;
}
}
return result;
}
@nabettu
Copy link
Author

nabettu commented May 27, 2015

How to use

getQueryString().変数名

example in http://example.com/?p=12

var pageId = getQueryString().p;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment