So if I have
http://example.com#something
how do I remove #something
?
doing window.location.hash = ''
removes the something
, but leaves the #
Edit: To be clear, I was hoping to accomplish this without refreshing the page
So if I have
http://example.com#something
how do I remove #something
?
doing window.location.hash = ''
removes the something
, but leaves the #
Edit: To be clear, I was hoping to accomplish this without refreshing the page
Initial question:
window.location.href.substr(0, window.location.href.indexOf('#'))
or
window.location.href.split('#')[0]
both will return the url without the hash or anything after it.
With regards to your edit:
Any change to window.location will trigger a page refresh. You can change window.location.hash without triggering the refresh (though the window will jump if your hash matches an id on the page), but you can't get rid of the hash sign. Take your pick for which is worse...