Skip to content

Instantly share code, notes, and snippets.

@bcls
Last active September 27, 2017 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcls/bdb283227ea30dbab9b353c1f67a61fa to your computer and use it in GitHub Desktop.
Save bcls/bdb283227ea30dbab9b353c1f67a61fa to your computer and use it in GitHub Desktop.
get URL param value #javascript
/**
* gets value of a URL param if exists
* @param {string} name the param you want the value of
* @return {string} result value of param if exists or ""
*/
function getURLparam(name) {
var regex,
results;
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment