Skip to content

Instantly share code, notes, and snippets.

@AlaaAttya
Created December 20, 2016 13:30
Show Gist options
  • Save AlaaAttya/75a6d99e2e8628db2df476836b11b921 to your computer and use it in GitHub Desktop.
Save AlaaAttya/75a6d99e2e8628db2df476836b11b921 to your computer and use it in GitHub Desktop.
Retrieve GET URL params
/**
* Read url parameters
*
* @link http://stackoverflow.com/a/901144/5734037
*/
var getUrlParameter = function (name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment