Skip to content

Instantly share code, notes, and snippets.

@MJ111
Last active January 10, 2018 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MJ111/184fe53bf624db06e50c67ad35e8c71d to your computer and use it in GitHub Desktop.
Save MJ111/184fe53bf624db06e50c67ad35e8c71d to your computer and use it in GitHub Desktop.
[get query param] #javascript
/**
* @param {string} name
* @returns {string|null}
* getQueryParam('a') returns '1' on page http://domain.com/page.html?a=1&b=2
**/
function getQueryParam(name) {
const q = window.location.search.match(
new RegExp('[?&]' + name + '=([^&#]*)')
);
return q && q[1];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment