title: HTML5 History API: "popstate" not called when navigating back from another page
body: <p>I have to maintain a site with an AJAX search form (for lets say books) and I want the search results to be a part of the browser history.</p>
  
  <p>So I set the <strong>"popstate"</strong> event handler</p>
  
  <pre><code>window.addEventListener('popstate', function(e) {
      alert("popstate: " + JSON.stringify(e.state));
  });
  </code></pre>
  
  <p>and call <strong>pushState()</strong> upon the successfull AJAX request: </p>
  
  <pre><code>var stateObj = { q: "harry potter" };
  window.history.pushState(stateObj, "Result", "/search");
  </code></pre>
  
  <p>Then my clickflow is:</p>
  
  <ol>
  <li>Load the page with the search form - NORMAL request - path is /</li>
  <li>Enter a query string and submit the form - AJAX request - path changes to <em>/search</em></li>
  <li>Click on a search result - NORMAL request - path changes to <em>/books/harry-potter</em></li>
  </ol>
  
  <hr>
  
  <ol start="4">
  <li><strong>When I now go <em>back</em> by clicking the browser back button I would expect the "popstate" event to be triggered with the according state object. But nothing happens.</strong> - <em>path changes to /search</em> </li>
  </ol>
  
  <hr>
  
  <ol start="5">
  <li><p>When I then go <em>back</em> one more time I get an alert with <code>popstate: null</code>  - <em>path changes to /</em></p></li>
  <li><p>And when I go <em>forward</em> after that, I get <code>popstate: {"q":"harry potter"}</code>  - <em>path changes to /search</em></p></li>
  </ol>
  
  <hr>
  
  <p><strong>So, the important popstate event (the one with the query string) gets only triggered when going forward, but not when going back.</strong> </p>
  
  <p>Is this because im navigating back from a site, whose history entry has been created automatically instead of programmatically by pushState?
  But if so, the History API would only make sense for complete single page applications.</p>
  
  <p>Behaviour is the same in any browser. Hope you can help me out :)</p>