Last active
February 20, 2018 05:58
-
-
Save Nully/1375966 to your computer and use it in GitHub Desktop.
URLの?以降(GET値)を取得する
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
// jQuery版に書き換えた | |
(function($){ | |
var queries = (function(){ | |
var s = location.search.replace("?", ""), | |
query = {}, | |
queries = search.split("&"), | |
i = 0; | |
if(!s) return null; | |
for(i; i < queries.length; i ++) { | |
var t = queries.split("="); | |
query[t[0]] = t[1]; | |
} | |
return query; | |
})(); | |
$.queryParameter = function(key) { | |
return (queries == null ? null : queries[key] ? queries[key] : null); | |
}; | |
})(jQuery); | |
// 使い方 | |
// URLが次のような場合 | |
// http://hogehoge.com/sample.js?theme=blue | |
$.queryParameter("theme"); // blueという文字列が取得できる | |
// 指定したキーがなければ... | |
$.queryParameter("hage"); // nullを返す |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment