Can I update window.location.hash without having the web page scroll?

Posted by Jonathon Watney on Stack Overflow See other posts from Stack Overflow or by Jonathon Watney
Published on 2009-03-14T02:21:55Z Indexed on 2010/06/14 23:22 UTC
Read the original article Hit count: 175

Using JavaScript, is there a way to update window.location.hash without scrolling the web page?

I have clickable title elements that toggle the visibility of a div directly beneath them. I want the /foo#bar in the history when clicking titles but don't want the page scrolling about. So when navigating away from /foo#bar I'll be able to use the back button and have the div whose ID is in window.location.hash be visible upon return.

Is this behavior possible?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about browser-history