Created
May 9, 2011 14:57
-
-
Save froop/962671 to your computer and use it in GitHub Desktop.
[JavaScript] 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 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