Home > Software engineering >  How to trigger a link in a tab of a table?
How to trigger a link in a tab of a table?

Time:12-18

When a user is on the home page, he can click on a link that redirects him to another page (so far, it works). In the new page, I would like the link to automatically open the second tab of a table by doing an "auto click" (trigger).

The link of the home page is specific (it has an anchor). I managed to make a script that works, the problem is that if I open this page from the navigation menu, the second tab of the table still opens.

I would like that only the specific link can automatically open the second tab of the table.

Landing Page Service Page

Here is the code I used:

$(document).ready(function(){
    $('#test').click(function(){
        console.log('clicked');
       });
     // set time out 5 sec
        setTimeout(function(){
           $('.et_pb_tab_3 > a').trigger('click');
       }, 500);
       console.log('triggered');
   });

Thanks a lot for helping.

Best regards,

Johann

CodePudding user response:

A url parameter may get the job done for you. From the link you want to open you could do something like: example-link.com?showTable=True.

Then look for that url parameter on the new page and only open if it's there and True.

example-link.com#rebozo?showTable=True

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const product = urlParams.get('showTable')
if (showTable && showTable === 'True') {
    // code to open the table
}

https://www.sitepoint.com/get-url-parameters-with-javascript/

CodePudding user response:

Ok so it was easy and i'd like to thanks @Branson Smith for inspiration.

i just had i conditional statement to check if there is a hash in the url :

if (window.location.hash == '#myHash') {
    $(document).ready(function(){
        $('#myID').click(function(){
            console.log('clicked');
           });
            setTimeout(function(){
               $('.myClass > a').trigger('click');
           }, 2000);
           console.log('triggered');
       });
};
  • Related