javascript: completely remove top.location.hash?
If I have already a hash in my addressbar like e.g. domain.com#whatever and I call:
top.location.hash = "";
the #wathever is transformed into domain.com# without anything.
Is it possible to completely remove the hash? So there is no #
开发者_如何学C left.
Because if I call top.location.hash = "";
the page jumps to it's top, because a # is passed to the url. I want to prevent that.
it's possible with history.pushState, e.g.:
history.pushState({}, '', './');
Of course it's IE<10 incompatible, but works for me :-)
top.location = ''
should do that, but it will cause a page reload. I don't think there's any way to remove it programmatically.
window.location = window.location.href.replace( /#.*/, "");
Unfortunately there is no way to reliably do so without causing the page to refresh, in which case you could use the location.href property.
精彩评论