Last active
October 2, 2018 21:29
-
-
Save kimbo/60eab96e141af5aa2b66fb17654f5ab1 to your computer and use it in GitHub Desktop.
Get url query string params in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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