Skip to content

Instantly share code, notes, and snippets.

@yoshifumi0521
Created December 6, 2012 03:13
Show Gist options
  • Save yoshifumi0521/4221543 to your computer and use it in GitHub Desktop.
Save yoshifumi0521/4221543 to your computer and use it in GitHub Desktop.
javascriptでパラメーターを取得するためのメソッド。getParameterメソッドを定義する。
//getParameterメソッドを定義する。
function getParameter(key) {
//パラメーターを配列で取得する。
var str = location.search.split("?");
if (str.length < 2) {
return "";
}
var params = str[1].split("&");
for (var i = 0; i < params.length; i++) {
var keyVal = params[i].split("=");
if (keyVal[0] == key && keyVal.length == 2) {
return decodeURIComponent(keyVal[1]);
}
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment