Created
April 25, 2012 17:49
-
-
Save unnamedd/2491630 to your computer and use it in GitHub Desktop.
Get Parameters from QueryString
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 getParameters(qs) { | |
qs = qs.split("+").join(" "); | |
var params = {}, tokens, | |
re = /[?&]?([^=]+)=([^&]*)/g; | |
while (tokens = re.exec(qs)) { | |
params[decodeURIComponent(tokens[1])] | |
= decodeURIComponent(tokens[2]); | |
} | |
return params; | |
/* Using: | |
var query = getParameters(document.location.search); | |
console.log(query.next) | |
*/ | |
} | |
String.prototype.format = function(){ | |
var pattern = /\{\d+\}/g; | |
var args = arguments; | |
return this.replace(pattern, function(capture){return args[capture.match(/\d+/)];}); | |
}; | |
String.prototype.contains = function(texto){ | |
return this.indexOf(texto) != -1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment