M
M
m0skit2015-12-11 06:17:15
Bootstrap
m0skit, 2015-12-11 06:17:15

Bootstrap tabs. How can I make the previously selected tab remain active when reloading the page?

Tell me how to make the previously selected tab, after reloading the page, remain active.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
m0skit, 2015-12-13
@m0skit

As long as you wait for an answer, you can give birth.
Found the solution myself. Maybe someone will come in handy.
Everything is done elementary, just add a script to the page.

$(document).ready(function() {
    if(location.hash) {
        $('a[href=' + location.hash + ']').tab('show');
    }
    $(document.body).on("click", "a[data-toggle]", function(event) {
        location.hash = this.getAttribute("href");
    });
});
$(window).on('popstate', function() {
    var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
    $('a[href=' + anchor + ']').tab('show');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question