Skip to content

Instantly share code, notes, and snippets.

@culttm
Created July 6, 2016 13:12
Show Gist options
  • Save culttm/a139d270db5fb68ff4123f58044a5c0b to your computer and use it in GitHub Desktop.
Save culttm/a139d270db5fb68ff4123f58044a5c0b to your computer and use it in GitHub Desktop.
function _updateQueryStringParameter(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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment