title: history pushState and scroll position
body: <p>I am trying to retrieve the scroll position when a user navigates back in the browser history using HTML5 popstate handler.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>$(document).ready(function () {
  
      $(window).on('popstate', PopStateHandler);
  
      $('#link').click(function (e) {
  
          var stateData = {
              path: window.location.href,
              scrollTop: $(window).scrollTop()
          };
          window.history.pushState(stateData, 'title', 'page2.html');
          e.preventDefault();
  
      });
  
  });
  
  function PopStateHandler(e) {
      alert('pop state fired');
      var stateData = e.originalEvent.state;
      if (stateData) {
          //Get values:
          alert('path: ' + stateData.path);
          alert('scrollTop: ' + stateData.scrollTop);
      }
  }
  
  
  &lt;a id="link" href="page2.html"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>When I navigate back, I am unable to retrieve the values of the stateData.</p>
  
  <p>I presume this is because the popstate is retrieving the values of the initial page load and not the state I pushed to the history when the hyperlink was clicked.</p>
  
  <p>How could I go about getting the scroll position on navigating back?</p>