Created
May 27, 2015 04:14
-
-
Save nabettu/0eafdfe1c7d2c22b2d9a to your computer and use it in GitHub Desktop.
GET的にURLに入っている内容を取得する。
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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use
getQueryString().変数名
example in http://example.com/?p=12
var pageId = getQueryString().p;