Javascript

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:

http://gallitin.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:

http://gallitin.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

Leave a Reply