Skip to content

Instantly share code, notes, and snippets.

@bcls
Created November 3, 2017 19:01
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/a3608836b0f55327027ba4bfaaa947fc to your computer and use it in GitHub Desktop.
Save bcls/a3608836b0f55327027ba4bfaaa947fc to your computer and use it in GitHub Desktop.
get value for URL param #javascript
/**
* gets value of a URL param on current page URL 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