1

I have a url that user goes to http://www.test.com/test/test#design/test

I want to remove the hash from the url without reloading the page, so that users are now on http://www.test.com/test/test

How can I do that using javascript/jquery?

J K
  • 4,883
  • 6
  • 15
  • 24
  • 3
    Possible duplicate of [How to remove the hash from window.location with JavaScript without page refresh?](http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh) – Andreas Aug 17 '16 at 17:36
  • What about window.location.href = 'http://www.test.com/'; ? – Jitesh Sojitra Aug 17 '16 at 17:37
  • duplicate of this too: http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page – Rob Allen Aug 17 '16 at 17:41

2 Answers2

1

Try window.history.pushState('', '/', window.location.pathname); and fallback to window.location.hash = '' if push state is not supported, but this will leave the trailing #.

if(window.history.pushState) {
    window.history.pushState('', '/', window.location.pathname)
} else {
    window.location.hash = '';
}
Chris Gunawardena
  • 6,246
  • 1
  • 29
  • 45
0

Try this code:

window.history.pushState("","", "#");
Arun D
  • 2,369
  • 5
  • 27
  • 39
  • You can't do this if you need to support IE 9 or lower http://caniuse.com/#feat=history – KVM Aug 17 '16 at 17:51