Skip to content

Instantly share code, notes, and snippets.

@asserchiu
Created July 24, 2013 19:26
Show Gist options
  • Save asserchiu/6073669 to your computer and use it in GitHub Desktop.
Save asserchiu/6073669 to your computer and use it in GitHub Desktop.
/**
* 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