Search the blog

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);
Tim Bennett is a web designer and developer. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.