简体   繁体   中英

How can I achieve an autoclick with Javascript / Jquery after being redirected to my homepage url?

I am looking for a way for my Jquery / Javascript to autoclick on the navigation bar of my home page, after sending the user to that main URL, from a page to detail.

I put an example of my code, the code redirects me to the home, but does not trigger the autoclick, or even a function that I indicate after having loaded the new url.

<li id="menu-item-406" class="historia-link menu-item menu-item-type-custom menu-item-object-custom menu-item-406">
    <a href="#">HISTORIA<span class="menu-description"></span></a>
</li>
<li id="menu-item-407" class="special-link menu-item menu-item-type-custom menu-item-object-custom menu-item-407">
    <a href="#">CACHORROS<span class="menu-description">/ Perros Disponibles</span></a>
</li>
<li id="menu-item-408" class="special-link menu-item menu-item-type-custom menu-item-object-custom menu-item-408">
    <a href="#">MACHOS<span class="menu-description">/ Sementales y Jóvenes</span></a>
</li>
jQuery(document).ready(function ($) {
    // Redirección submenu
    $('#menu-item-406, #menu-item-407, #menu-item-408').click(function () {
        if (this.id == 'menu-item-406') {
            window.location = "https://vonmarlu.com/von-marlu/";
            $('#menu-item-38 a').trigger('click');
        } else if (this.id == 'menu-item-407') {
            window.location = "https://vonmarlu.com/von-marlu/";
            $(window).on("load", function () {
                $('#home').fadeOut(1000);
                $('#cachorros').fadeOut(1000);
                $('#adultos').fadeOut(1000);
                $('#trabajo').fadeOut(1000);
                $('#hembras').fadeOut(1000);

                $("#historia").css('display', 'block');
                $("#historia").animate({
                    opacity: "1"
                }, 800);
                $(".about-left-section").css('z-index', '10');
                $(".about-left-section").animate({
                    left: "0px"
                }, 1200);
                $(".about-left-section").css('left:', '0');
                $(".about-right-section").css('z-index', '5');
                $(".about-right-section").delay(800).animate({
                    left: "0px"
                }, 1500);
                $(".about-right-section").css('left:', '0');
            };
        }
        else if (this.id == 'menu-item-408') {
            alert('Submit 3 clicked');
        }
    });
});

I use a conditional to validate that when I click on an ID of my main menu, The code will execute the functions that I ask, only that I do not know if it is the best way to achieve it.

Any ideas that have worked for you? I'm a bit lost in this.

Here: trigger('click') will initiate a click event.

<script type="text/javascript">
    $(function(){
        $('#id').trigger('click');
    });
</script>

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