Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Created November 26, 2019 11:38
Show Gist options
  • Save Farmatique/d9e77afd8e4d63c95ceb0197fe2d3d4a to your computer and use it in GitHub Desktop.
Save Farmatique/d9e77afd8e4d63c95ceb0197fe2d3d4a to your computer and use it in GitHub Desktop.
Get query strings from 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, ' '));
};
// from url like sales/?search=roadmap+mcp+test
// using getUrlParameter('search') it return "roadmap mcp test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment