Skip to content

Instantly share code, notes, and snippets.

@devfred
Created December 14, 2015 17:52
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 devfred/518bb556b104e5b5bd90 to your computer and use it in GitHub Desktop.
Save devfred/518bb556b104e5b5bd90 to your computer and use it in GitHub Desktop.
var UpdateQueryStringParameter = function(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
};
@brndto
Copy link

brndto commented Jul 25, 2018

https://gist.github.com/sgreenfield/2802070 <-- another good one you can use to make improvements to yours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment