Here is another way to solve the problem.
First add a line to the click event to show the hash in the address bar:
$('#myTab').on('click', 'a', function (e) {
e.preventDefault();
// Add this line
window.location.hash = $(this).attr('href');
$(this).tab('show');
})
Then make sure that the right tab is activated onload
by adding this part to your document ready call.
if(window.location.hash){
$('#myTab').find('a[href="'+window.location.hash+'"]').tab('show');
}
All together you can write this:
// Cache the ID
var navbox = $('#myTab');
// Activate tab on click
navbox.on('click', 'a', function (e) {
var $this = $(this);
// Prevent the ***default*** behavior
e.preventDefault();
// Set the hash to the address bar
window.location.hash = $this.attr('href');
// Activate the clicked tab
$this.tab('show');
})
// If we have a hash in the address bar
if(window.location.hash){
// Show right tab on load (read hash from address bar)
navbox.find('a[href="'+window.location.hash+'"]').tab('show');
}