title: Updating address bar window.location hash with scrollspy
body: <p>I've got a menu with scrollspy (using twitter boostrap). I want update the <code>window.location.hash</code> when the user scrolls down to a next section.</p>
  
  <p>The following code works when the user scrolls down:</p>
  
  <pre><code>$(window).on('activate.bs.scrollspy', function (e) {
    location.hash = $("a[href^='#']", e.target).attr("href") || location.hash;
  });
  </code></pre>
  
  <p>However it does not work very well when the user scrolls upwards.</p>
  
  <p>The reason for this is that setting a new <code>location.hash</code> triggers the browser to navigate towards that respective anchor. That triggers a chain reaction in which the user will instantly end up at the top of the page.</p>
  
  <p><a href="http://jsfiddle.net/n8Hk9/2/" rel="nofollow">Demo in js-fiddle</a></p>
  
  <p>Now what would be the simplest way to solve that problem?</p>