jQuery UI tabs, update url when clicking on a different tab

前端 未结 8 792
甜味超标
甜味超标 2020-12-09 11:56

I\'m using the tabs of jQuery UI: http://jqueryui.com/demos/tabs/

How to update the current url of the browser when the user click on a different ta

8条回答
  •  死守一世寂寞
    2020-12-09 12:37

    Building off of Jeff B's work above...this works with jQuery 1.11.1.

    $("#tabs").tabs(); //initialize tabs
    $(function() {
        $("#tabs").tabs({
            activate: function(event, ui) {
                var scrollTop = $(window).scrollTop(); // save current scroll position
                window.location.hash = ui.newPanel.attr('id'); // add hash to url
                $(window).scrollTop(scrollTop); // keep scroll at current position
        }
    });
    });
    

提交回复
热议问题