Last active
January 10, 2018 04:35
-
-
Save MJ111/184fe53bf624db06e50c67ad35e8c71d to your computer and use it in GitHub Desktop.
[get query param] #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
/** | |
* @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