<!DOCTYPE html>
<html>

<head>
  <title>Linkable Tabs</title>
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" />

</head>

<body>
  <div class="container">
    <h1>Linkable Tabs</h1>
    
    <div role="tabpanel">

      <!-- Nav tabs -->
      <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
        <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
        <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
        <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
      </ul>
    
      <!-- Tab panes -->
      <div class="tab-content">
        <div role="tabpanel" class="tab-pane fade in active" id="home">Home Text</div>
        <div role="tabpanel" class="tab-pane fade" id="profile">Profile Text</div>
        <div role="tabpanel" class="tab-pane fade" id="messages">Messages Text</div>
        <div role="tabpanel" class="tab-pane fade" id="settings">Settings Text</div>
      </div>
    
    </div>
    
  </div>
  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
  <script src="script.js"></script>
</body>

</html>
$(function() {
  
    // jump to tab if it exists 
    if (location.hash) {
        $('a[href=' + location.hash + ']').tab('show');
    }
    
    // add tab hash to url to persist state
    $(document.body).on("shown.bs.tab", function(e){
      location.hash = e.target.hash;
    });
    
});

/* on history back activate the tab of the location hash if exists or the default tab if no hash exists */
$(window).on('popstate', function() {
    var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
    $('a[href=' + anchor + ']').tab('show');
});	
/* Styles go here */