Remember which tab was active after refresh

前端 未结 17 2245
眼角桃花
眼角桃花 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条回答
  •  悲哀的现实
    2020-11-27 05:17

    I am resolved the same issue with the help of following blog.

    HTML Tab

     
    

    Javascript

     var selectedTab =  window.location.href.split("#tab=")[1] ;
        var selectedId = $('a[href$=' + selectedTab+']:first').attr('id');
    
        if (typeof selectedId === "undefined") {
             $('#tab1-tab').trigger("click");
        }
        else{
            $('#'+selectedId).trigger("click");
        }
    

    For me it worked, suggestion appreciated.

提交回复
热议问题