javascripthtml

How to remove id (#) target after refresh


I have a user flow which the user will fill out a form on index.html and then click on next to go to index.html/#step2

However, I would like the user to go back to index.html, instead of staying on index.html/#step2, if the user hits the refresh button.

Is there any way to force them to go back to index.html?

Thanks


Solution

  • You could probably do it by setting the location hash to an empty string every time the page loads.

    <script type="text/javascript">
        window.onload = function() {
            document.location.hash = "";
        }
    </script>