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:
<!DOCTYPE html> <html> <head> <title> How to remove hash from windoow.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:

Recommended Posts:
- Refresh a page using PHP
- How to refresh a page using jQuery?
- How to refresh parent page on closing a popup ?
- How to refresh a file in Node.js ?
- What’s the best way to reload / refresh an iframe?
- How to display search result of another page on same page using ajax in JSP?
- How to show Page Loading div until the page has finished loading?
- How to redirect a page to another page in HTML ?
- How to pass form variables from one page to other page in PHP ?
- How to modify URL without reloading the page using JavaScript ?
- How to reload CSS without reloading the page using JavaScript ?
- How to add Google map inside html page without using API key ?
- How to Remove URL from Printing the Page ?
- How to remove .html extension from URL of a static page ?
- How to create hash from string in JavaScript ?
- How to disable right click on web page using JavaScript ?
- Scroll to the top of the page using JavaScript/jQuery
- Open all persons solution links from submission page using JavaScript
- How to disable dragging an image from an HTML page using JavaScript/jQuery ?
- How to run a function when the page is loaded in JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


