Skip to content

Instantly share code, notes, and snippets.

@Xusifob
Last active May 10, 2017 10:15
Show Gist options
  • Save Xusifob/025df295573aad9fcc622a801799fe65 to your computer and use it in GitHub Desktop.
Save Xusifob/025df295573aad9fcc622a801799fe65 to your computer and use it in GitHub Desktop.
Returns an query parameter
/**
*
* Get the url parameter
*
* @param parameter
* @returns {string|undefined}
*/
function getUrlParameter(parameter) {
var params_string = window.location.search.substr(1);
var params_array = params_string.split('&');
var obj = {};
for(var i =0;i<params_array.length;i++)
{
var e = params_array[i].split('=');
obj[e[0]] = e[1]
}
var o = obj[parameter];
return o ? decodeURIComponent(o.replace(/\+/g, '%20')) : o;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment