Skip to content

Instantly share code, notes, and snippets.

@akaramires
Created November 20, 2013 09:05
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 akaramires/7560042 to your computer and use it in GitHub Desktop.
Save akaramires/7560042 to your computer and use it in GitHub Desktop.
function insertUrlParams(uri, key, value) {
var re = new RegExp("([?|&])" + key + "=.*?(&|$)", "i");
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