Created
November 16, 2018 16:09
-
-
Save jeandcr/e6adf084a3970a92e3a3c834a48d03e1 to your computer and use it in GitHub Desktop.
Return a URL query string by key.
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
| /** | |
| * | |
| * Returns a URL query parameter by it's key. | |
| * eg. You have a URL: http://host.com/some/path?uniquekey=value | |
| * The function call qs('uniquekey') returns 'value' | |
| * | |
| * @param key string | |
| * @return string | |
| * | |
| */ | |
| function qs(key) { | |
| key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars | |
| var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)")); | |
| return match && decodeURIComponent(match[1].replace(/\+/g, " ")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment