You might want to look into jQuery Cookie.
Assuming HTML along these lines:
<ul class="tabs">
<li class="tab" id="tab1">
...
</li>
<li class="tab" id="tab2">
...
</li>
</ul>
this would work:
$(document).ready(function(){
$('.tab').click(function(){
// show correct tab, hide other tabs ...
$.cookie('selected_tab', $(this).attr('id')); // save information in a cookie
});
current_tab = $.cookie('selected_tab'); // read and cache information from cookie
if (current_tab != null)
{
$('#' + current_tab).trigger('click'); // trigger the tab click handler, thereby restoring the tab
}
});
Another option would be to attach an anchor to each link's URL that signifies the currently selected tab and evaluate it on page load:
$(document).ready(function(){
$('.tab').click(function(){
// show correct tab, hide other tabs ...
var current_id = $(this).attr('id'); // cache the current tab id
$('a').each(function(i,e){ // add a hash '#tab=tab1' to each link in the page
hrf = $(e).attr('href');
if (hrf) {
$(e).attr('href', hrf.split('#')[0] + '#tab=' + current_id);
});
});
});
current_tab = document.location.hash.split('tab=')[1];
if (current_tab) // if '#tab=foo' is present in the URL
{
$('#' + current_tab).trigger('click'); // trigger the tab click handler, thereby restoring the tab
}
});
This approach obviously has its own problems, though (i.e. the inability to use hashed links as those get overwritten).