Created
December 6, 2012 03:13
-
-
Save yoshifumi0521/4221543 to your computer and use it in GitHub Desktop.
javascriptでパラメーターを取得するためのメソッド。getParameterメソッドを定義する。
This file contains 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
//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