Javascript Reload Page on Click Without Query String

By July 31, 2017 No Comments

Here is an example of how to reload a page on button click with Javacript and removing the query string.

I have a page like this:

I want to be able to click a “Reset” button to start over by removing the query string:

Here is an example of how to do this:

<!DOCTYPE html> <html> <body> <a href="#" id="reload">Click to reload without query string</a> <script> document.getElementById("reload").onclick = function() {reload()}; function reload() { window.location = window.location.href.split("?")[0]; } </script> </body> </html>

Demo it here

Leave a Reply