Skip to main content

Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #277856
    vulkanus
    Participant

    Hi everyone,

    Anyone can help me to develop a little code to prevent trigger button in mobile?

    I have a menu accordion it open with js, so, when we press the button to open submenu for the first time, it opens, then if it clicks again it will trigger the url

    I want to avoid that, only fire the URL when we quick double click.

    Here an example: https://codepen.io/Vulkanus/pen/YJYvQY

    Do this:
    1 – press “submenu” text
    2 – press “submenu2” text
    3 – Then press “submenu” text again.

    Thank you

    #277860
    chris_2080
    Participant

    Hi,

    You can try this:

    $("ul#primary-menu > li.menu-item-has-children").on("click", function(e)     {
            return false;
        }).dblclick(function(e) {
            var win = window.open($(this).children().attr('href'), '_blank');
            win.focus();
            return false;
        });
    

    https://codepen.io/chris3000/pen/wYjxjO

    #277861
    vulkanus
    Participant

    @chris_2080

    Thank you very much, it´s Perfect!
    Fits like a glove :)

    Best regards.

    #277941
    vulkanus
    Participant

    Hi @chris_2080

    Good day,

    Can I ask you something else?
    I need the href of the submenu, trigger only the first click, not as it is in the parent.

    Parent href == 2 clicks
    Child (submenu) href == click

    Thank you once more.
    cumps

    #277942
    chris_2080
    Participant

    Hi @vulkanus

    If I understood you correctly:

    $(".sub-menu > .menu-item").one("click", function(e)     {
           e.preventDefault();
           alert($(this).children().attr('href'));
           return false;    
       });
    
    #277943
    vulkanus
    Participant

    @chris_2080

    Thank you

    with the excerpt of your code, I adapted, this line, is what I want

     window.open($(this).children().attr('href'), '_self');
    

    basically the parent has to trigger the second click, the child to the first

    With the full code, can be optimized?

    $(“ul#primary-menu > li.menu-item-has-children”).one(“click”, function(e) {
    e.preventDefault();
    return false;
    });

    $(“ul#primary-menu > li.menu-item-has-children”).on(“click”, function(e) {
    return false;
    }).dblclick(function(e) {

       window.open($(this).children().attr('href'), '_self');
        return false;
    })
    $(".sub-menu > .menu-item").one("click", function(e)     {
     window.open($(this).children().attr('href'), '_self');
     return false;    
    

    });

    #277944
    chris_2080
    Participant

    @vulkanus

    you can combine it:

    $('ul#primary-menu > li.menu-item-has-children').one('click', function(e) {
        e.preventDefault();
        return false;
    }).on('click', function(e) {
        return false;
    }).dblclick(function(e) {
        window.open($(this).children().attr('href'), '_self');
        return false;
    });
    
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.