How to remove hash from window.location with JavaScript without page refresh ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The replaceState() method is used to modify the current history entry, replacing it with the state objects, title, and URL passed in the method parameters. This method is useful when you want to update the state object or URL of the current history entry in response to some user action. To remove the hash URL, you can use the replaceState method on the history API to remove the hash location.Example: HTML <!DOCTYPE html> <html> <head> <title> How to remove hash from window.location with JavaScript without page refresh? </title> </head> <body style="text-align: center;"> <h1 style="color: green"> GeeksforGeeks </h1> <p> How to remove the hash from window.location</br> with JavaScript without page refresh? </p> <p> Click on the button to modify the current history state </p> <button onclick="modifyState()"> Modify history state </button> <button onclick="remove_hash_from_url()"> Remove hash from url </button> <script> function modifyState() { let stateObj = { id: "100" }; window.history.replaceState(stateObj, "Page 3", "/answer#page3.html"); } function remove_hash_from_url() { var uri = window.location.toString(); if (uri.indexOf("#") > 0) { var clean_uri = uri.substring(0, uri.indexOf("#")); window.history.replaceState({}, document.title, clean_uri); } } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to refresh a page using selenium JavaScript ? N NikhilChandwani Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to reload CSS without reloading the page using JavaScript ? While working with CSS, you might have come across situations where you made some changes in the stylesheet and had to do a hard reload to see the changes reflected in your browser. Or maybe the style depends on some user interaction and you don't wish to hard reload the page every time. Sometimes y 2 min read How to refresh a page using selenium JavaScript ? Selenium is a tool with the help of it, we can perform automation testing in web browsers. According to the official documentation of Selenium - Selenium can automate anything present on the web. Automation scripts in Selenium can be written in multiple programming languages like C#, JavaScript, Jav 2 min read How to modify URL without reloading the page using JavaScript ? In this article, we are going to see how to modify URL without reloading the page using JavaScript Below are the methods to modify the URL without reloading the page using JavaScript: Table of Content Replacing the current state with replaceState() MethodAdding a new state with pushState() MethodMet 3 min read How to Display Changed Browser URL Without Reloading Through alert using JavaScript ? To change the URL in the browser without loading the new page, we can use history.pushState() method and replaceState() method from JavaScript. To display the browser-URL before changing the URL we will use window.location.href in the alert() function and will use again after changing the browsers-U 1 min read How to submit a form or a part of a form without a page refresh using jQuery? How to prevent an HTML form to submit?When submitting a form, clicking the submit button usually navigates to a new route as specified in the form's action attribute. However, this can be done in the background using event.preventDefault(), which blocks the default event behavior. By attaching an on 2 min read How to clear form after submit in Javascript without using reset? Forms in JavaScript serve to gather specific user information, essential in various contexts like recruitment or inquiry submissions. While offline forms can be freely distributed, online forms must maintain a consistent structure for all users. After filling out a form, submission is crucial, but d 2 min read Like