Created
September 25, 2011 13:34
-
-
Save kiyotakagoto/1240605 to your computer and use it in GitHub Desktop.
【JavaScript 】 URIパラメータをオブジェクトにする
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 uri_parameter_string_to_object ( uri_param_string_with_question_mark ) { | |
| var uri_param_string_without_question_mark | |
| , uri_param_name_equal_value_array | |
| , uri_param_container | |
| , param_name_equal_value_string | |
| , param_name_and_value_set | |
| , uri_param_name | |
| , uri_param_value | |
| , length | |
| , i = 0 | |
| ; | |
| // delete '?' | |
| uri_param_string_without_question_mark | |
| = uri_param_string_with_question_mark.replace('?', ''); | |
| // split by '&', make array of 'param_name=value's. | |
| uri_param_name_equal_value_array | |
| = uri_param_string_without_question_mark.split('&'); | |
| // create uri_param object, like { param_name : value } | |
| uri_param_container = {}; | |
| length = uri_param_name_equal_value_array.length; | |
| for ( ; i < length; ++i ) { | |
| param_name_equal_value_string = uri_param_name_equal_value_array[i]; | |
| param_name_and_value_set = param_name_equal_value_string.split('='); | |
| uri_param_name = param_name_and_value_set[0]; | |
| uri_param_value = param_name_and_value_set[1]; | |
| uri_param_container[uri_param_name] = uri_param_value; | |
| } | |
| return uri_param_container; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment