Skip to content

Instantly share code, notes, and snippets.

@johnvicencio
Last active August 18, 2020 21:49
Show Gist options
  • Save johnvicencio/3c9da70a4e73f38c3036fc0ed13c454c to your computer and use it in GitHub Desktop.
Save johnvicencio/3c9da70a4e73f38c3036fc0ed13c454c to your computer and use it in GitHub Desktop.
Notebook
Query String
//get's a query parameter by name from current url
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
//example
var userSearch=getUrlParameter('search_term');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment