Created
August 18, 2012 19:39
-
-
Save nus/3389269 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 parseURLParams() { | |
var params_str = location.search.slice(1); | |
if(params_str.length < 1) { | |
return ''; | |
} | |
var items = {}; | |
var items_str = params_str.split(/[&;]/); | |
for(var i = 0, l = items_str.length; i < l; i++) { | |
var p = items_str[i]; | |
var item = p.split('='); | |
if(item.length == 2) { | |
var key = decodeURIComponent(item[0]); | |
var value = decodeURIComponent(item[1]); | |
items[key] = value; | |
} | |
} | |
return items; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment