Skip to content

Instantly share code, notes, and snippets.

@bitgord
Created December 13, 2016 02:35
Show Gist options
  • Save bitgord/b988379930a79729984540d0a4ee0f97 to your computer and use it in GitHub Desktop.
Save bitgord/b988379930a79729984540d0a4ee0f97 to your computer and use it in GitHub Desktop.
Get Query Params Third Party Lib
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i=0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
return undefined;
}
// to run // http://localhost:3000/?name=Michael&lastname=Gord
// from console get name and lastname // getQueryVariable('name'); // getQueryVariable('lastname');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment