title: How can I ignore window.onpopstate on page load?
body: <p>I'm playing with <code>window.onpopstate</code>, and there is a thing that annoys me a little bit:</p>
  
  <blockquote>
    <p>Browsers tend to handle the popstate event differently on page load.
    Chrome and Safari always emit a popstate event on page load, but
    Firefox doesn't.</p>
  </blockquote>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/DOM/window.onpopstate" rel="noreferrer">source</a></p>
  
  <p>I tested it, and yeah, in Chrome and Safari 5.1+ the popstate event is fired on page load, but not in Firefox or IE10.</p>
  
  <p>The problem is, that I want to listen only to <code>popstate</code> events where user clicked the <em>back</em> or <em>forward</em> button (or the history was changed via javascript), but don't want to do anything on pageload.</p>
  
  <p>By other words I want to differentiate the <code>popstate</code> event from <em>page load</em> from the other <code>popstate</code> events.</p>
  
  <p>This is what I tried so far (I'm using jQuery):</p>
  
  <pre><code>$(function() {
    console.log('document ready');
  
    setTimeout(function() {
      window.onpopstate = function(event) {
        // Do something here
      }, 10);
  });
  </code></pre>
  
  <p>Basically I try to bind my <code>listener</code> function to <code>popstate</code> late enough to be not bound on page load, only later.</p>
  
  <p>This seems to work, however, I don't like this solution. I mean, how can I be sure that the <em>timeout</em> chosen for setTimeout is big enough, but not too big (because I don't want it to wait too much).</p>
  
  <p>I hope there is a smarter solution!</p>