function updateURLParam(uri, key, value) {

var re = new RegExp(“([?&])” + key + “=.*?(&|$)”, “i”);
var params = uri.indexOf(‘?’) !== -1 ? “&” : “?”;

if (uri.match(re)) {
return uri.replace(re, ‘$1’ + key + “=” + value + ‘$2’);
} else {
return uri + params + key + “=” + value;
}

}

Advertisements