Skip to main content

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

I have a URL like this:

domain.com/experts-exchange/29046174.php?id=1&query=nathan&orgID=2442

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

domain.com/experts-exchange/29046174.php

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

Need more help?  Check out our Custom Web Development in Kansas City.

Leave a Reply