ASP.NET postbacks lose the hash in the URL

后端 未结 3 947
再見小時候
再見小時候 2021-02-20 02:14

On an ASP.NET page with a tabstrip, I\'m using the hash code in the URL to keep track of what tab I\'m on (using the BBQ jQuery plugin). For example:

http://mysi         


        
3条回答
  •  执笔经年
    2021-02-20 03:10

    I have another solution, implemented and tested with chrome, IE and safari.

    I am using the "localStorage" object and it suppose to work all the browsers which support localStorage.

    On the click event of tab, I am storing the currentTab value to local storage.

    $(document).ready(function() {
            jQuery('.ctabs .ctab-links a').on('click', function(e) {
                var currentAttrValue = jQuery(this).attr('href');
                localStorage["currentTab"] = currentAttrValue;
    
                // Show/Hide Tabs
                jQuery('.ctabs ' + currentAttrValue).show().siblings().hide();
    
                // Change/remove current tab to active
                jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
    
                e.preventDefault();
            });
            if (localStorage["currentTab"]) {
                // Show/Hide Tabs
                jQuery('.ctabs ' + localStorage["currentTab"]).show().siblings().hide();
                // Change/remove current tab to active
                jQuery('.ctabs .ctab-links a[href$="' + localStorage["currentTab"] + '"]').parent('li').addClass('active').siblings().removeClass('active');
            }
        });
    

提交回复
热议问题