title: Enable Back Button Handling With Twitter Bootstrap Tabs in IE8+
body: <p>Bootstrap 2.3.2 </p>
  
  <p>I am using <a href="http://getbootstrap.com/2.3.2/javascript.html#tabs" rel="noreferrer">tabs</a> from Bootstrap in my project to display content. On a single page there are multiple tabs with different content and in those tabs are links to take the user to other pages on the website. </p>
  
  <p>Unfortunately by default, the tabs don't support back button navigation, so if a user visits another page and hits the browser's back button, the tab will have reverted to the first open tab rather than the one that was active when they last viewed the page.</p>
  
  <p>The Javascript below from <a href="http://redotheweb.com/2012/05/17/enable-back-button-handling-with-twitter-bootstrap-tabs-plugin.html" rel="noreferrer">François Zaninotto</a> solves this problem in Chrome, Firefox and Safari. François also says it works for IE8+ - but during my tests I can't get it to work on IE8, IE9 or IE10. Does anyone know how to get this working in IE8+ ? Is it possible?</p>
  
  <pre><code>$(document).ready(function() {
    // add a hash to the URL when the user clicks on a tab
    $('a[data-toggle="tab"]').on('click', function(e) {
      history.pushState(null, null, $(this).attr('href'));
    });
    // navigate to a tab when the history changes
    window.addEventListener("popstate", function(e) {
      var activeTab = $('[href=' + location.hash + ']');
      if (activeTab.length) {
        activeTab.tab('show');
      } else {
        $('.nav-pills a:first').tab('show');
      }
    });
  });
  </code></pre>
  
  <p>`</p>
  
  <pre><code>    &lt;ul id="myTab" class="nav nav-pills"&gt;
                &lt;li class="active"&gt;&lt;a href="#tab1" data-toggle="tab"&gt;Tab1&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href="#tab2" data-toggle="tab"&gt;Tab2&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#tab3" data-toggle="tab"&gt;Tab3&lt;/a&gt;&lt;/li&gt;
  
              &lt;/ul&gt;
  
  &lt;div id="myTabContent" class="tab-content"&gt;
                &lt;div class="tab-pane active" id="tab1"&gt;
                    &lt;h2&gt;Tab 1&lt;/h2&gt;
                  &lt;p&gt;Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.&lt;/p&gt;
                &lt;/div&gt;
                &lt;div class="tab-pane" id="tab2"&gt;
                    &lt;h2&gt;Tab 2&lt;/h2&gt;
                  &lt;p&gt;Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.&lt;/p&gt;
                &lt;/div&gt;
                &lt;div class="tab-pane" id="tab3"&gt;
                      &lt;h2&gt;Tab 3&lt;/h2&gt;
                  &lt;p&gt;Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.&lt;/p&gt;
                &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>