Skip to content

Instantly share code, notes, and snippets.

@adam-lynch
Last active December 17, 2015 12:48
Show Gist options
  • Save adam-lynch/5611955 to your computer and use it in GitHub Desktop.
Save adam-lynch/5611955 to your computer and use it in GitHub Desktop.
Gets the value of a GET argument (URL parameter). Returns undefined if the argument doesn't exist. Like the $_GET superglobal array in PHP.
/**
* Gets the value of a GET argument (URL parameter). Returns undefined if the argument doesn't exist
*
* @param name string
* @returns string|undefined
*
* @author adam-lynch
*/
function _GET( name ){
var regexS = "[\\?&]" + name.replace( /[\[]/, "\\\[" ).replace( /[\]]/, "\\\]" ) + "=([^&#]*)",
results = (new RegExp( regexS )).exec( window.location.search );
return results && decodeURIComponent( results[1].replace( /\+/g, " " ) ) || undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment