Removing the query string without refreshing the page can used, for example, instead of a redirect to prevent something happening again if the page is refreshed. window.history
allows you to do this.
At the time of writing window.history
is available on all major browsers excluding Opera Mini.
Remove the query string and keep it in the history
window.history.pushState({}, document.title, window.location.pathname);
Remove the query string and remove it from the history
window.history.replaceState({}, document.title, window.location.pathname);
