Skip to content

Instantly share code, notes, and snippets.

@marios88
Created February 21, 2018 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marios88/2fd500e8ea49b2f5f7ce54b16b9438df to your computer and use it in GitHub Desktop.
Save marios88/2fd500e8ea49b2f5f7ce54b16b9438df to your computer and use it in GitHub Desktop.
Boostrap v4 tab history
$(function(){
//refresh && link
var hash = window.location.hash;
hash && $('.nav a[href="' + hash + '"]').tab('show');
//back - forward
window.onpopstate = function(event) {
if(window.location.hash == ''){
//no hash in url show the tab you like!
$('.nav a[href="#nav-home"]').tab('show');
}else{
$('.nav a[href="' + window.location.hash + '"]').tab('show');
}
}
$('.nav-tabs a').click(function (e) {
$(this).tab('show');
var scrollmem = $('body').scrollTop() || $('html').scrollTop();
window.location.hash = this.hash;
$('html,body').scrollTop(scrollmem);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment