title: hashchange only when not from click
body: <p>I'm using this</p>
  
  <pre><code>$(window).bind('hashchange', gotohash);
  </code></pre>
  
  <p>to add deep linking to my app.</p>
  
  <p>My problem is that it also fires when I click an <code>&lt;a&gt;</code> with <code>href=#whatever</code>
  and I only want to use it when the user uses the back and forward buttons of the browser or goes directly to a url with hash in it.</p>
  
  <p>I'm thinking of <code>hashChangeEnabled=true/false</code> and then turn it off on every click</p>
  
  <p>but is there an easier way to detect whether it's caused by click or not? </p>
  
  <p>What is the best practice?</p>
  
  <hr>
  
  <p><strong>My Solution</strong></p>
  
  <pre><code>var disableHashChange = false;
  
  $(window).bind('hashchange', function(){
    if(!disableHashChange ){
      gotohash();
    }
    disableHashChange = false;
  });
  
  $('.link').click(function(){
    disableHashChange = true;
  }
  </code></pre>
  
  <p><strong>Answer</strong> by imsky</p>
  
  <pre><code>var lastLinkEvent;
  
  $(window).bind('hashchange', function(){
    if(lastLinkEvent != window.location.hash){
      gotohash();
      lastLinkEvent = "";
    }
  });
  
  $('.link').click(function(){
      lastLinkEvent = $(this).attr('href');;
  }
  </code></pre>
  
  <p>Thanks</p>