JavaScript

Refresh browser window without query parameters

Published on August 29th, 2020


If you want to reload the current page in your browser without any query string or parameters, here's how you can do it:


window.location = window.location.pathname;

By doing so, it'll preserve the HTTP/HTTPS protocols of the URL and also remove the fragments that start with a #.

If you want to preserve the fragments, you can try this:


var reloadURL = window.location.pathname;
var fragments = (window.location.part === undefined) ? "" : "#" + window.location.part;
window.location = reloadURL + fragments;

Hope you found this useful!