1var searchParams = new URLSearchParams(window.location.search);
2searchParams.set("foo", "bar");
3window.location.search = searchParams.toString();
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//You can reload the url like so
12 var newUrl=updateQueryStringParameter(window.location.href,"some_param","replaceValue");
13 window.history.pushState("", "Page Title Here", newUrl);