简体   繁体   English

重定向到首页网址后,如何使用Javascript / Jquery实现自动点击?

[英]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. 我正在寻找一种方法,让我的Jquery / Javascript在将用户发送到该主要URL(从页面到详细信息)后,自动单击主页的导航栏。

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. 我使用一个条件来验证,当我单击主菜单的ID时,该代码将执行我所要求的功能,只是我不知道这是否是实现它的最佳方法。

Any ideas that have worked for you? 有什么想法对您有用吗? I'm a bit lost in this. 我对此有些迷茫。

Here: trigger('click') will initiate a click event. 此处:trigger('click')将启动click事件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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