MyBB Community Forums

Full Version: Remember the tab where a user was
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,
I followed this tutorial and all works but, for example, when I refresh the page I also return to the main tab and not where I was before refreshing. I think this can be resolved with cookies, but I don't know how to do.

Could you help me? Thanks
Target tabs using IDs and use jQuery cookie to remember the states following this tutorial:

http://community.mybb.com/thread-120082.html
Thank you effone but I don't know where exactly I have to add the lines in your linked tutorial.

I already have this code:

<script type="text/javascript" src="jscripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$.noConflict();
</script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.tab').click(function(){
$('.at').removeClass('at');
$(this).addClass('at');
$('.content').slideUp();
var catshow = $(this).attr('rel');
$('#'+ catshow).slideDown();
});
});
</script>

<table border="0" cellpadding="0" cellspacing="0">
<tr align="center">
<td width="15">
<td class="button at tab" title="General" style="vertical-align: middle; cursor: pointer; color: #000" rel="cat_1"><span style="font-weight: bold; line-height: 15px">General</span></td>

<td class="button tab" title="PC" style="cursor: pointer; color: #000" rel="cat_64"><span style="font-weight: bold; line-height: 15px">PC</span></td>

I have to add only this line?
jQuery.cookie("openclose","closed", {expires: 365}); // sets cookie
and then obviously the cookie-check? And where?
You have to save the state this way on each tab's .click() function:

jQuery.cookie("tab{$tab_id}","opened", {expires: 365}); // sets cookie

And call the state on pageload

jQuery(*).removeClass('at');
if(jQuery.cookie("tab{$tab_id}") == "opened") {
        jQuery("tab{$tab_id}").addClass('at');
    };

Note: this is just an example. Modify as per your own. I've not gone in depth.