Skip to content

Instantly share code, notes, and snippets.

@troyericg
Created March 20, 2015 15:51
Show Gist options
  • Save troyericg/8ade76535a81c2c6f941 to your computer and use it in GitHub Desktop.
Save troyericg/8ade76535a81c2c6f941 to your computer and use it in GitHub Desktop.
two ways to grab querystrings using pure js
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