Created
January 26, 2018 04:28
-
-
Save kouhot/7441ffa35056856b5dac520ed8f4189c to your computer and use it in GitHub Desktop.
Get value of specific query from URL with JavaScript
This file contains hidden or 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
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