Created
October 21, 2020 22:03
-
-
Save ano/ac302f4288d4b76ff0de1ae331828ac6 to your computer and use it in GitHub Desktop.
Javascript $_GET() - similar in nature to PHP $_GET[]
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
| /** | |
| * Description: Gets a URL parameter value. Similar to PHP $_GET | |
| * @param {string} param | |
| */ | |
| function $_GET(param) { | |
| var vars = {}; | |
| window.location.href.replace(location.hash, '').replace(/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp | |
| function (m, key, value) { // callback | |
| vars[key] = value !== undefined ? value : ''; | |
| }); | |
| if (param) { | |
| return vars[param] ? vars[param] : null; | |
| } | |
| return vars; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment