Skip to content

Instantly share code, notes, and snippets.

@ano
Created October 21, 2020 22:03
Show Gist options
  • Select an option

  • Save ano/ac302f4288d4b76ff0de1ae331828ac6 to your computer and use it in GitHub Desktop.

Select an option

Save ano/ac302f4288d4b76ff0de1ae331828ac6 to your computer and use it in GitHub Desktop.
Javascript $_GET() - similar in nature to PHP $_GET[]
/**
* 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