2020. 1. 9. 10:14

[jQueryUI Tab] Page Refresh 후에도 Tab이 변하지 않는 방법

var currentTab = window.location.hash.substring(1);
var tabIndex = ["RequiredDocuments", "AdditionalDocuments"];
$( "#tabs" ).tabs({
    create: function(event, ui) {
        var index = ui.tab.index();
        window.location.hash = tabIndex[index];
    },
    activate: function(event, ui) {
        var index = ui.newTab.index();
        window.location.hash = tabIndex[index];
    },
    active: currentTab.length !== 0 && tabIndex.hasOwnProperty(currentTab) ? tabIndex.indexOf(currentTab) : 0
});

구버전은 아래처럼.

var currentTab = window.location.hash.substring(1);
var tabIndex = ["RequiredDocuments", "AdditionalDocuments"];
$("#tabs").tabs({
    show: function(event, ui) {
        window.location.hash = tabIndex[ui.index];
    },
    selected: currentTab.length !== 0 && tabIndex.hasOwnProperty(currentTab) ? tabIndex.indexOf(currentTab) : 0
});