Search code examples
javascriptbrowser-historyback-buttondeep-linking

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


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?


Solution

  • This behavior is very much possible. You should look into some of the libraries that have been developed to give you this functionality.

    Really Simple History: http://code.google.com/p/reallysimplehistory/ SWFAddress: http://www.asual.com/swfaddress/