If I have already a hash in my addressbar like e.g. domain#whatever and I call:
top.location.hash = "";
the #wathever is transformed into domain# without anything.
Is it possible to pletely remove the hash? So there is no #
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.
If I have already a hash in my addressbar like e.g. domain.#whatever and I call:
top.location.hash = "";
the #wathever is transformed into domain.# without anything.
Is it possible to pletely remove the hash? So there is no #
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.
- without reloading the page? I'd say no – Guillaume86 Commented Mar 21, 2011 at 20:59
4 Answers
Reset to default 3it's possible with history.pushState, e.g.:
history.pushState({}, '', './');
Of course it's IE<10 inpatible, 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.