Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created June 7, 2010 15:47
Show Gist options
  • Save thinkphp/428828 to your computer and use it in GitHub Desktop.
Save thinkphp/428828 to your computer and use it in GitHub Desktop.
/* Utilities */
if(!String.prototype.parseQueryString) {
String.prototype.parseQueryString = function() {
var mix = {};
var vars = this.split(/[&;]/);
if(vars.length > 0) {
vars.each(function(val){
var key = val.split("=");
if(key.length && key.length == 2) {
mix[key[0]] = key[1];
}
});
}
return mix;
};
}
function getQueryStringValue(key) {
try {
return getQueryStringValues()[key];
}catch(e){return null;}
};
function getQueryStringValues(){
var win = document.location.href;
//get query string
var qs = win.split("?")[1];
try{
if(qs){return qs.parseQueryString();}
}catch(e){return null;}
};
@sindresorhus
Copy link

You shouldn't extend String.prototype.

Use https://github.com/sindresorhus/query-string instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment