Created
July 24, 2013 19:26
-
-
Save asserchiu/6073669 to your computer and use it in GitHub Desktop.
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
/** | |
* documentLocationSearch2Dic | |
* -------------------------- | |
* | |
* Convert `document.location.search` string into key-values | |
* | |
* @param {String} documentLocationSearch document.location.search | |
* @return {Object} key-values of search strings | |
*/ | |
function documentLocationSearch2Dic(documentLocationSearch) { | |
'use strict'; | |
var dic = {}; | |
// NOTE: The HTTP protocol does not place any a priori limit on the length of a URI. -- rfc2616 | |
var list = documentLocationSearch.substr(1, Number.POSITIVE_INFINITY).split('&'); | |
var i = list.length; | |
while (i--) { | |
dic[list[i].split('=')[0]] = list[i].split('=')[1]; | |
} | |
return dic; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment