1function setParam(uri, key, val) {
2 return uri
3 .replace(RegExp("([?&]"+key+"(?=[=&#]|$)[^#&]*|(?=#|$))"), "&"+key+"="+encodeURIComponent(val))
4 .replace(/^([^?&]+)&/, "$1?");
5}
1function updateQueryStringParameter(uri, key, value) {
2 var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
3 var separator = uri.indexOf('?') !== -1 ? "&" : "?";
4 if (uri.match(re)) {
5 return uri.replace(re, '$1' + key + "=" + value + '$2');
6 }
7 else {
8 return uri + separator + key + "=" + value;
9 }
10}
11