Javascript: completely remove top.location.hash?

Hey guys, quick question, I could not find anything useful on the Internet.

if I already have a hash in my address bar, for example, for example. domain.com # whatever, and I'm calling ...

top.location.hash = "";

#wathever converts to domain.com # without anything.

Is it possible to completely remove the hash? So there is no #left.

Because if I call top.location.hash = "";, the page jumps up because # the URL is passed. I want to prevent this.

+3
source share
4 answers
top.location = ''

should do this, but it will cause the page to reload. I don’t think there is a way to remove it programmatically.

+2
source

possibly using history.pushState, for example:

history.pushState({}, '', './');

, IE , : -)

+3
window.location = window.location.href.replace( /#.*/, "");
0
source

Unfortunately, there is no way to reliably do this without forcing the page to refresh, in which case you can use the location.href property.

0
source

All Articles