Howto remove the location hash without causing the page to scroll

Posted . Visible to the public.

Set the hash to a dummy hash which doesn't hit any id at your page, for example:

window.location.hash = "_";

Note

  • If you'd set the hash to "" it causes the page to scroll to the top because the hash "#" by itself is equivalent to "_top".
  • If you'd set window.location.href = "..." to get rid of the "#", you cause the browser to reload the page what is most likely not intended.
Martin Straub
Last edit
Keywords
javascript
License
Source code in this card is licensed under the MIT License.
Posted by Martin Straub to makandra dev (2013-07-05 12:27)