Opening JQuery tabs with URL, and adding a hash to URL on tab click

牧云@^-^@ 提交于 2019-12-03 07:11:55

I ended up using the JQuery Address plugin from Asual. I did the following:

    // For forward and back
    $.address.change(function(event){
        $("#main_tabs").tabs( "select" , window.location.hash );
    });

    // when the tab is selected update the url with the hash
    $("#main_tabs").bind("tabsselect", function(event, ui) { 
        window.location.hash = ui.tab.hash;
    });

Hopefully this helps someone! Thank you.

You can also try in the following way. I have name property in the anchor element. This name will be added as hash URL.

Javascript:

$( "#tabs" ).tabs({
    select: function(event, ui) {                   
        window.location.hash = ui.tab.hash;                     
    }
});

HTML:

<div id="tabs" > 
    <ul>
        <li><a name="Test1" href="Home/Test1"> Tab 1  </a></li>
        <li><a name="Test2" href="Home/Test2"> Tab 2  </a></li>
        <li><a name="Test3" href="Home/Test3"> Tab 3  </a></li>            
    </ul>        
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!