• Shirts
    All geek questions in one place

    Link to a specific tab from another page

    I have a form with 3 tabs

    <div class="tabs"> <ul class="tabset"> <li><a class="active"><span>Shirts</span></a></li> <li><a href="#"><span>Jeans</span></a></li> <li><a href="#"><span>Shoes</span></a></li> </ul> <div id="1"> <p> Shirts </p> </div> <div id="2"> <p> Jeans</p> </div> <div id="3"> <p> Shoes</p> </div> </div> 

    I would like to be able to link to a specific tab from the results page and make it an active tab. I know that I should use the query string in the url from the link link of the result page.

    So, if I have 3 category results pages, and each of them has a link to a form like:

      <a href="./redefine?tab=id1"></a> <a href="./redefine?tab=id2"></a> <a href=".redefine?tab=id3"></a> 

    What code do I need to use on the form page to make sure this works. I read that I need to make sure with jquery it checks to see if the parameter exists and uses location.hash, but not sure how to do it.

    +4
    javascript jquery tabs
    gek Mar 09 '12 at 15:44
    source share
    4 answers

    Use and capture location.hash will not contain # id1, so just trigger that id

     var hash = location.hash; // Get the hashtag if(hash!=""){ // See if it contain something jQuery(hash.replace("#","")).trigger("click") // Remove # char from it and put the result as the selector.. } 
    0
    Simon edstrรถm Mar 09 '12 at 15:51
    source share

    There is no outbound link in the code snippet. If you are trying to display new content on a page without making another HTTP request, you are not dependent on the URL. Just save your status in some variables.

    0
    Amberlamps Mar 09 '12 at 15:53
    source share

    location.hash not a sequence of requests, but a binding link (with # included).

    This means that if you have a ./redefine page, the anchor can be ./redefine#1

    The request ?1 will force the browser to really go to the page, where #1 will just go to the id="1" page.

    Example: To show jQuery only show the correct page, you can do:

    HTML

     <div class="tabs"> <ul class="tabset"> <li><a class="active" href="#1"><span>Shirts</span></a></li> <li><a href="#2"><span>Jeans</span></a></li> <li><a href="#3"><span>Shoes</span></a></li> </ul> <div class="tab" id="1"> <p> Shirts </p> </div> <div class="tab" id="2"> <p> Jeans</p> </div> <div class="tab" id="3"> <p> Shoes</p> </div> </div> 

    Javascript

     $('.tab').hide(); $(window).bind('hashchange', function() { $('.tabset a').removeClass('active'); $('.tab').hide(); if (location.hash) { $('.tabset a[href="' + location.hash + '"]').addClass('active'); $(location.hash).show(); } }); 
    0
    user887675 Mar 09 '12 at 16:04
    source share

    To use the query string from jQueryUI tabbed url:

     $(function(){ /* get search string from url */ var query = location.search; var reg = /\?tab=id/; /* if search query use that value, if not use zero*/ var tab= (query && query!='#') ? query.replace(reg,'') -1 : 0; $('#tabs').tabs({ selected: tab}); }) 

    Use hash from jQueryUI tabbed url:

     $(function(){ /* get search string from url */ var query = location.hash; var reg = /\#/; /* if search query use that value, if not use zero*/ var tab= (query && reg.test(query)) ? query.replace(reg,'') -1 : 0; $('#tabs').tabs({ selected: tab}); }) 
    0
    charlietfl Mar 09 '12 at 16:14
    source share

    Source: https://habr.com/ru/post/1400602/

    More articles:

    • Why does Seq give a stack overflow on going through a large csv file - stack-overflow
    • Mule message for reading queue messages in Quartz Scheduler and forwarding to the Java component - mule
    • Tabs in fixed positions in JTabbedPane or on one line - java
    • Camel Apache: xpath to extract some value from the resulting XML - xpath
    • Working with named pipes in Windows (C ++ / C #) - c ++
    • https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1400603/adding-two-tables-to-a-word-document-directly-on-top-of-each-other&usg=ALkJrhiru7oj_ROw2ghQz_LZvU_FKF2RfA
    • Spring does not enter ServletContext - spring-mvc
    • Linq-to-sql code does not return results, even though - c #
    • jQuery Mobile List View: initialize error - jquery
    • C # java equivalent of Array.GetLength (i) - java

    All Articles

    Geek Questions | 2019