Skip to content

Instantly share code, notes, and snippets.

@Fabiantjoeaon
Created September 2, 2016 09:27
Show Gist options
  • Save Fabiantjoeaon/ed026d3c47e72a35c8ad9987c1b87e39 to your computer and use it in GitHub Desktop.
Save Fabiantjoeaon/ed026d3c47e72a35c8ad9987c1b87e39 to your computer and use it in GitHub Desktop.
ES6 retrieve GET parameters from URL
/**
* Retrieve parameter values from URL
* @param {name} name of paramater
* @param {url} URL to fetch parameter from | optional
* @returns URL param value || null
*/
const getURLParemeters = ( name, url ) => {
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
return results == null ? null : results[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment