Skip to content

Instantly share code, notes, and snippets.

@kouhot
Created January 26, 2018 04:28
Show Gist options
  • Save kouhot/7441ffa35056856b5dac520ed8f4189c to your computer and use it in GitHub Desktop.
Save kouhot/7441ffa35056856b5dac520ed8f4189c to your computer and use it in GitHub Desktop.
Get value of specific query from URL with JavaScript
const getParamByName = (name, url) => {
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment