简体   繁体   中英

Simulate a click from a link on another internal page

I have four images with links on my main page . I also have four matching galleries on another page that are hidden except for one at a time. Each gallery is shown when a specific image on that gallery page is clicked.

I am trying to get the home page images to link specifically to their corresponding galleries (such as clicking on the children image on the home page, will loadup the gallery page and display the children gallery).

I read these questions and tried to implement their answers:

https://stackoverflow.com/questions/2847185

https://stackoverflow.com/questions/7047746

The gallery page loads up using a carousel plugin and a custom script for my setup was created to allow the images/tabs(the class is img.imgslide and they do not have any ID property) on the carousel to show/hide galleries:

jQuery(document).ready(function() {
        if (jQuery('.customtabs > br').length) {
            jQuery('.customtabs > br').remove();
        }       
});

function displaycustom_tab(obj) {
        var totalSlides = jQuery(obj).parent().find('>div').length / 3;
        var tabi = 0;
        var slidei = jQuery(obj).index() + 1;
        if (slidei > (2 * totalSlides)) {
            tabi = slidei - (2 * totalSlides);
        } else if (slidei > (totalSlides)) {
            tabi = slidei - totalSlides;
        } else {
            tabi = slidei;
        }
        tabi--;
        jQuery('.customtabs > div').removeClass('activetab');
        jQuery('.customtabs > div:eq(' + tabi + ')').addClass('activetab');
    jQuery(window).trigger('resize');
}

I tried to use this code: The text wrapped with *s is my added code (with the *s).

jQuery(document).ready(function() {
        if (jQuery('.customtabs > br').length) {
            jQuery('.customtabs > br').remove();
        }       
        ****jQuery('#newborn').get(0).click();****
});

I get this error in Chromes Inspect panel :

gallery.js:5 Uncaught TypeError: Cannot read property 'click' of undefined

I'm not sure how to get this working. Do I need to create an attribute property for the ID field on the carousel tabs?

Looked through the source of the link you posted. Looks like you might be using the wrong ID.

jQuery('#newborn').get(0).click();

should be

jQuery('#newbornlink').get(0).click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM