0

i am trying to have the last selected tab, after page refresh. My code is below.By this code always first tab is in active after page reload.

javascript

<script>
      $(function() {
      $( "#tabs" ).tabs();
      });

    </script>

html:

<body>
    <div id='childarpt' class='childarpt' ></br>
    <div id="tabs"><ul>
    <li class="active"><a href="#Total"><span>Total</span></a></li>
    <li><a href="#USA"><span>USA</span></a></li>
    <li><a href="#ASIA"><span>ASIA</span></a></li>
    <li><a href="#JAPAN"><span>JAPAN</span></a></li>
    <li><a href="#LATAM"><span>LATAM</span></a></li>
    <li><a href="#EMEA"><span>EMEA</span></a></li>
    </ul>
    <table id='myTable' border='0'>

     <div id="Total" class="tab active">
     Total
     </div>
     <div id="USA" class="tab">
     USA
    </div>
    <div id="ASIA" class="tab">
    ASIA
    </div>
    <div id="JAPAN" class="tab">
    JAPAN
     </div>
      <div id="LATAM" class="tab">
      LATAM
     </div>
     <div id="EMEA" class="tab">
     EMEA
    </div>

     </table>
     </div>
     </body>
elreeda
  • 4,525
  • 2
  • 18
  • 45
sravani reddy
  • 45
  • 1
  • 2
  • 9
  • 3
    You may store the Tab ID in a cookie or something , so you can retrieve it later . Check Here : http://stackoverflow.com/questions/4299435/remember-which-tab-was-active-after-refresh – Ashraf Apr 17 '16 at 08:58

3 Answers3

1

A quick and dirty solution to your issue

$(function() {
  var tabs = $( "#tabs" )
  tabs.tabs({
    activate: function(e,ui) {
      var index = ui.newTab.index()
      location.hash = index;
    },
    active: location.hash.replace(/#/,"") || 0
  });
});

You will need to change the storing and loading of the state, but this will set you off.

Torben Pi Jensen
  • 850
  • 9
  • 27
0

Instead of

$(function() { $( "#tabs" ).tabs(); });

Try this:

$( "#tabs" ).tabs({ active: 5 });

This will make the sixth (it is zero-indexed) tab the default active tab.


for your reference : http://api.jqueryui.com/tabs/

anjaneyulubatta505
  • 10,713
  • 1
  • 52
  • 62
0

Refer to Bootstrap 3: Keep selected tab on page refresh, it contains all the information you need to implement what you want.

The idea is to store the selected tab in the hashvalue of the window. Change the hash of the location when another tab is selected.

Community
  • 1
  • 1
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400