Created
June 7, 2010 15:47
-
-
Save thinkphp/428828 to your computer and use it in GitHub Desktop.
This file contains 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
/* 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;} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You shouldn't extend String.prototype.
Use https://github.com/sindresorhus/query-string instead.