title: history.js stops firing statechange event after pressing back button 2 times
body: <p>One of my customer has a lot of webistes based on lots of CMS (Wordpress, Drupal and so on). He wanted a generic directory, where professionals can register and share information. It is "generic", as it can be installed on any website (declined according to the website's business). </p>
  
  <p>I developed it inside an iframe, as this can be installed on any CMS, and there were other good reasons to do it this way (CSS, SEO...). But as iframe-browsing is transparent for the navigation bar, I needed to do some tricks to allow visitors to copy/paste professionals's urls, share and fav them. I used history.js to update the navbar's URL, and when direct-accessing the iframe I redirect the user to the right "main website"'s page.</p>
  
  <p>But my problem come when clicking the "back" button. For some reasons, the "<code>statechange</code>" event is not properly fired when clicking "back" a second time. </p>
  
  <h2>I developed a demo, you can see <a href="http://so.ocarina.fr/test/main.html" rel="nofollow">my problem live here</a>, and you can <a href="http://so.ocarina.fr/test.zip" rel="nofollow">download it here</a>.</h2>
  
  <p>As you can see on the log div, when you click B and C, you'll get:</p>
  
  <pre><code>Push: /a.html
  Push: /b.html
  statechange trigered
  Push: /c.html
  statechange trigered
  </code></pre>
  
  <p>If you go back once, you'll get:</p>
  
  <pre><code>statechange trigered
  Pop: /b.html
  </code></pre>
  
  <p>And if you go back a second time, you'll get:</p>
  
  <pre><code>Push: /c.html
  statechange trigered
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>statechange trigered
  Pop: /a.html
  </code></pre>
  
  <p>So my question:</p>
  
  <blockquote>
    <p>What is going on here ?</p>
  </blockquote>
  
  <p><kbd>main.html</kbd></p>
  
  <pre><code>&lt;iframe id="my-test" src="a.html" width="500" height="500"&gt;&lt;/iframe&gt;
  
  &lt;div id="log"&gt;&lt;/div&gt;
  
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="//cdnjs.cloudflare.com/ajax/libs/jquery-browser/0.0.6/jquery.browser.min.js"&gt;&lt;/script&gt;
  &lt;script src="history.js/scripts/bundled/html4+html5/jquery.history.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  
      var test_url = 'http://so.ocarina.fr/test';
  
      // used to avoid listening events trigered by the script itself
      var manual_state_change = true;
  
      // used to avoid pushing the previous page
      var is_back = false;
  
      $(document).ready(function () {
          $('#my-test').load(function () {
  
              // when iframe has loaded, we replace the navbar's url by
              // the one from iframe's source.
  
              if (!window.is_back) {
                  window.manual_state_change = false;
  
                  var History = window.History;
                  if (History.enabled) {
  
                      var url = $('#my-test').get(0).contentWindow.location.href;
                      if (url.indexOf('blank') &gt; 0) {
                          return;
                      }
                      if (url.indexOf('test') &gt; 0) {
                          url = url.substring(url.indexOf('test') + 4);
                          if (url.length === 0) {
                              url = '/';
                          }
                      }
  
                      $('#log').append('Push: ' + url + '&lt;br/&gt;');
  
                      var title = $("#my-test").contents().find("title").html();
                      document.title = title;
                      History.pushState({url: decodeURIComponent(url + '')}, title, window.test_url + decodeURIComponent(url + ''));
  
                      window.manual_state_change = true;
                  }
              }
              window.is_back = false;
  
          }).trigger('load'); // triggered once to replace main.html by a.html
  
          var History = window.History;
          if (History.enabled) {
              History.Adapter.bind(window, 'statechange', function () {
  
                  // if user clicks back, we should change the iframe's location
                  // to the backward url from history stack.
  
                  $('#log').append('statechange trigered &lt;br/&gt;');
  
                  if (window.manual_state_change === true) {
                      window.manual_state_change = false;
                      var state = History.getState();
                      var url = state.data.url;
                      $('#log').append('Pop: ' + url + '&lt;br/&gt;');
                      window.is_back = true;
                      $('#my-test').attr('src', window.test_url + url);
                      $('#my-test')[0].contentWindow.location = window.test_url + url;
                      window.manual_state_change = true;
                  }
  
              });
          }
  
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p><kbd>a.html</kbd></p>
  
  <pre><code>&lt;title&gt;Test A&lt;/title&gt;
  
  &lt;script type="text/javascript"&gt;
      if (top.location === self.location) {
          window.location = 'main.html';
      }
  &lt;/script&gt;
  
  &lt;div id="content"&gt;
  
      &lt;p&gt;This is test A&lt;/p&gt;
  
      &lt;a href="b.html"&gt;Go to test B&lt;/a&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><kbd>b.html</kbd></p>
  
  <pre><code>&lt;title&gt;Test B&lt;/title&gt;
  
  &lt;script type="text/javascript"&gt;
      if (top.location === self.location) {
          window.location = 'main.html';
      }
  &lt;/script&gt;
  
  &lt;div id="content"&gt;
  
      &lt;p&gt;This is test B&lt;/p&gt;
  
      &lt;a href="c.html"&gt;Go to test C&lt;/a&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><kbd>c.html</kbd></p>
  
  <pre><code>&lt;title&gt;Test C&lt;/title&gt;
  
  &lt;script type="text/javascript"&gt;
      if (top.location === self.location) {
          window.location = 'main.html';
      }
  &lt;/script&gt;
  
  &lt;div id="content"&gt;
  
      &lt;p&gt;This is test C&lt;/p&gt;
  
      &lt;p&gt;Go back to A using your backward button...&lt;/p&gt;
  
  &lt;/div&gt;
  </code></pre>