tags:

views:

355

answers:

1

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

+1  A: 

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...

Gabriel Hurley
This is just plain wrong, you can change window.location.hash and it will not trigger a refresh.
Evgeny
@Evgeny -- That's what my answer says. I explicitly say that changing window.location.hash won't trigger a 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)".
Gabriel Hurley