Created
March 20, 2015 15:51
-
-
Save troyericg/8ade76535a81c2c6f941 to your computer and use it in GitHub Desktop.
two ways to grab querystrings using pure js
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
function splitURL(){ | |
var query = window.location.search.substring(1), | |
vars = query.split("&"), | |
params = {}, | |
p; | |
for (var i=0; i<vars.length;i++){ | |
p = vars[i].split("="); | |
params[ p[0] ] = p[1]; | |
}; | |
return params; | |
}; | |
function regexURL(){ | |
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), | |
results = regex.exec(window.location.search); | |
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment