You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.
history. pushState({page: "another"}, "another page", "example. html"); This will change the URL, but not reload the page.
The URLSearchParams interface defines utility methods to work with the query string of a URL.
window.location = window.location.href.split("?")[0];
There are a few ways to go about it:
window.location = window.location.href.split("?")[0];
Or, alternatively:
window.location = window.location.pathname;
This is the best and easiest way,
// similar to HTTP redirect
window.location.replace(location.pathname);
I typically try to avoid making unnecessary function calls whenever I can, especially when the information I need is already provided to me by the DOM. That said, here is probably objectively the best solution:
window.location = window.location.pathname + window.location.hash;
As pointed out in a comment by user qbert65536, there are many popular modern frameworks that use the hash to denote views and paths, which is why using window.location.pathname
alone is not enough.
Try this Javascript:
location = location.pathname;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With