K
K
KomunistIvan2018-05-27 20:07:44
Bootstrap
KomunistIvan, 2018-05-27 20:07:44

Nav-tabs how to stay on the same tab after applying changes?

I have nav-tabs on bootstrap 4, in the second tab I have a field with a filter, after applying the filter it throws it to the first tab, but if you then return to the second tab again, we will see that the filter worked. It remains only to do that after reloading the page, to remain on the same tab on which it was last time. There are many such questions on the Internet, and it is solved with the help of a script, but each script needs a specific nav-tabs.
I do everything on bootstrap 4, and my knowledge in php and javascript is 2 out of 10. Could you help me with my example? Thanks in advance.

<!-- Nav tabs -->
<ul class="nav nav-tabs" id="myTab">
  <li class="nav-item cont">
    <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">{PHP.L.Main}</a>
  </li>
  <li class="nav-item cont">
    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">{PHP.L.projects_projects} {USERS_DETAILS_PROJECTS_COUNT}</a>
  </li>
  <li class="nav-item cont">
    <a class="nav-link" id="messages-tab" data-toggle="tab" href="#messages" role="tab" aria-controls="messages" aria-selected="false">{PHP.L.reviews_reviews} {USERS_DETAILS_REVIEWS_COUNT}</a>
  </li>
  <li class="nav-item cont">
    <a class="nav-link" id="settings-tab" data-toggle="tab" href="#settings" role="tab" aria-controls="settings" aria-selected="false">{PHP.L.market} {USERS_DETAILS_MARKET_COUNT}</a>
  </li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">
     {USERS_DETAILS_PM}
  </div>
  <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">
      {PROJECTS}
  </div>
  <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">
      {REVIEWS}
  </div>
  <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">
      {MARKET}
  </div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Sevirinov, 2018-05-28
@KomunistIvan

Use cookie or localStorage or sessionStorage to store the selected tab.
For example like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question