Last active
December 17, 2015 12:48
-
-
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.
This file contains 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
/** | |
* 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