Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save atilacamurca/cf3fdb9d1cf0eb53c3e27cabf022a91a to your computer and use it in GitHub Desktop.
Save atilacamurca/cf3fdb9d1cf0eb53c3e27cabf022a91a to your computer and use it in GitHub Desktop.
$(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-tabs a:first').tab('show');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment