Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Created September 27, 2017 10:42
Show Gist options
  • Select an option

  • Save gemmadlou/7ec85a458bb0bc927f1329e037777cd8 to your computer and use it in GitHub Desktop.

Select an option

Save gemmadlou/7ec85a458bb0bc927f1329e037777cd8 to your computer and use it in GitHub Desktop.
Parse Params Function Stolen
/**
* JavaScript Get URL Parameter
*
* @param String prop The specific URL parameter you want to retreive the value for
* @return String|Object If prop is provided a string value is returned, otherwise an object of all properties is returned
*/
function getParam(str, prop) {
let params = {};
let search = decodeURIComponent(str);
let definitions = search.split( '&' );
definitions.forEach( function( val, key ) {
var parts = val.split( '=', 2 );
params[parts[ 0 ]] = parts[ 1 ];
} );
return (prop && prop in params) ? params[ prop ] : params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment