There where multiple Questions and solutions for the Tab container should keep the last selected tab instead of refreshing the whole page and starting in the first tab again. But the solutions i had wont work with my page. Can someone help me out?
This is my JS
<script type="javascript">
$(function() {
// for bootstrap 3 use 'shown.bs.tab', for bootstrap 2 use 'shown' in the next line
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
// save the latest tab; use cookies if you like 'em better:
localStorage.setItem('lastTab', $(this).attr('href'));
});
// go to the latest tab, if it exists:
var lastTab = localStorage.getItem('lastTab');
if (lastTab) {
$('[href="' + lastTab + '"]').tab('show');
}
});
</script>
And that’s my HTML:
<ul id="myTab" class="nav nav-tabs" role="tablist" style="background-color: #3E98E4;">
<li role="presentation" class="active"><a href="#kunver" aria-controls="kunver" role="tab" data-toggle="tab" style=" border: 1px solid;
margin-top: 10%;
color: #fff;
background-color: #3C97E4;">Kunden</a></li>
<li role="presentation"><a href="#erter" aria-controls="erter" role="tab" data-toggle="tab" style=" border: 1px solid;
margin-top: 10%;
color: #fff;
background-color: #3C97E4;">Termine</a></li>
<a href="logout.php" ><button style="margin-top: 1%;margin-left:1%;
background-color: #3E98E4;
color: #fff;
border-color: #fff;" type="button" class="btn btn-default" data-toggle="tooltip" data-placement="right" title="Tooltip on right"><span class="glyphicon glyphicon-log-out"></span> Logout</button></a>
</ul>
3
Answers
Well I’ve made few modifications to your code and it will be as below:
DEMO
UPDATE
Using native
.tab('show')
method you can do it as below but again you need to removeactive class
from previousdefault element
UPDATED DEMO
You could just change the hash:
The url will be updated and when the refresh button is clicked it should open the correct tab.
if you have more than one tab in the page, you can use the following code