Skip to content

Instantly share code, notes, and snippets.

@zach-taylor
Created October 24, 2016 18:02
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 zach-taylor/da1ff57d6178907100a77701445bdc5a to your computer and use it in GitHub Desktop.
Save zach-taylor/da1ff57d6178907100a77701445bdc5a to your computer and use it in GitHub Desktop.
function to add or update a query parameter
var updateQueryParam = function(query_param, new_value) {
var re = new RegExp('(' + query_param + '=)[^\\&]*');
if (re.test(location.href)) {
location.href = location.href.replace(re, '$1' + new_value);
} else {
location.href = location.href + '?' + query_param + '=' + new_value;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment