12 responses to “jQuery tabs and cookies”

  1. Dave

    This line:
    show: function(ui) {
    should be:
    show: function(junk,ui) {
    for jquery 1.2.6 I believe. The ui object is now the second parameter.

  2. Alien Y

    fix some…
    work with jQuery 1.2.6 and ui-Tabs 1.5

    var tab_cookie_id = parseInt($.cookie(“the_tab_cookie”)) || 0;
    $(“#container-1 > ul”).tabs({
    selected: tab_cookie_id,
    show: function(e, ui) { var tab_id = ui.index; $.cookie(“the_tab_cookie”, tab_id, { expires: 30}); }
    });

  3. Alien Y

    I rewrite for ui Tab3.0 + jQuery 1.2.6

    var tab_cookie_id = parseInt($.cookie(“the_tab_cookie”)) || 0;

    $(“#container-1 > ul”).tabs({
    selected: tab_cookie_id,
    select: function(e, ui) { if (ui.index == 0 && tab1_use_ == 1) {/* do some thing */}
    },
    show: function(e, ui) { var tab_id = ui.index; $.cookie(“the_tab_cookie”, tab_id, { expires: 30 }); }
    });

  4. PP

    thx Alien Y :)

  5. Marian Bida

    Don’t try it, just use it, it is working good..

  6. Nick Clarke

    Just to let you know this is now built into the current release for tabs. To use all I had to do was:

    $(‘#example > ul’).tabs({cookie: {expires: 7}})

    Hope this helps

  7. Michele

    Nick: I have been looking for this for soooo long!Simple and straightforward. Thank you.

  8. the666bbq

    hallelujah … I’ve spent too much time on the named cookie thing too ;-) I’m a jQuery evangelist whenever I can but the documentation on how to use custom named cookies (instead of ui-tabs-something) is not sufficient if you ask my opinion ;-) . This snippet is exactly what I needed … thanks guys.

    what is that ‘something’-integer in “ui-tabs-something” anyway … it comes from $.data(this.list[0]) but who/where/what is that set ??

    wouldn’t it be nice if we could just ‘set’ the cookie name to be used “out of the box” (and if we develoeprs are lazy or not in need for flexibility the plugin can use the default ui-tabs-whatever)

    Peter

  9. NatNac

    Nick: Fine, very short. But the name of the cookie is ui-tabs%5Bob0ject%20Object%5D for all tabs in the same domain. I have about 15 tabs. There must be an easy way to create one cookie per tab with the name of the selector.

  10. NatNac

    I’ve tried the other examples. The following script creates a named cookie. Wow. But the value in the cookie (index of tab) is always undefined. What’s wrong.

    I habe jquery 1.71 and tab 3.0

    var tab_cookie_id = parseInt($.cookie(“ui-tabs_user”)) || 0;
    $(function () {
    $(“#user > ul”).tabs({selected: tab_cookie_id});
    $(“#user > ul”).bind(‘tabsshow’, function(event, ui) { var tab_id = ui.index; $.cookie(“ui-tabs_user”, tab_id, { expires: 1});});

Leave a Reply