Remember which tab was active after refresh

前端 未结 17 2249
眼角桃花
眼角桃花 2020-11-27 04:43

I\'m using jquery tabs on a web page and when the page is refreshed it loses what ever tab I had been on and goes back to the first tab.

Has anyone come across this

17条回答
  •  旧时难觅i
    2020-11-27 05:24

    Now that cookie is gone in jQuery UI 1.10.0, I mixed Gayathiri's approach with the new options and events:

    // using cookie plugin from https://github.com/carhartl/jquery-cookie
    
    var tabCookieName = "ui-tabs-1";
    $(".tabs").tabs({
        active : ($.cookie(tabCookieName) || 0);
        activate : function( event, ui ) {
            var newIndex = ui.newTab.parent().children().index(ui.newTab);
            // my setup requires the custom path, yours may not
            $.cookie(tabCookieName, newIndex, { path: window.location.pathname });
        }
    });
    

提交回复
热议问题