Skip to content

Instantly share code, notes, and snippets.

@kimbo
Last active October 2, 2018 21:29
Show Gist options
  • Save kimbo/60eab96e141af5aa2b66fb17654f5ab1 to your computer and use it in GitHub Desktop.
Save kimbo/60eab96e141af5aa2b66fb17654f5ab1 to your computer and use it in GitHub Desktop.
Get url query string params in javascript
// using URLSearchParams
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
let urlParams = new URLSearchParams(window.location.search);
let something = url_params.get('something');
// other way (also works with window.location.hash)
let urlParams = {};
window.location.search.substr(1).split('&').forEach((param) => {
let x = param.split('=');
urlParams[x[0]] = x[1];
});
let something = urlParams.['something']; // or urlParams.something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment