Skip to content

Instantly share code, notes, and snippets.

@adamdehaven
Created October 30, 2020 19:35
Show Gist options
  • Save adamdehaven/839aa87c7bfb718ba736e372e88bbd2e to your computer and use it in GitHub Desktop.
Save adamdehaven/839aa87c7bfb718ba736e372e88bbd2e to your computer and use it in GitHub Desktop.
Get URL query string parameter values
/**
* Return the value of a URL parameter
* @param url String
* @param key String
*/
const getUrlParam = (url, key) => {
const results = new RegExp('[?&]' + key + '=([^&#]*)').exec(url)
return results ? decodeURI(results[1]) : null
};
// Get the URL
const url = window.location.href
// Usage
if (getUrlParam(url, 'success')) {
// Do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment