Javascript not working on mobile but works on desktop

后端 未结 4 975
名媛妹妹
名媛妹妹 2021-01-13 07:56

This works on a desktop browser, but not on my iOS mobile phone. I tried adding \'touchstart\' and looked at this post\'s solution to check how other\'s got it to work, but

相关标签:
4条回答
  • 2021-01-13 08:31

    Put e.preventDefault(); inside your javascript function.

    0 讨论(0)
  • 2021-01-13 08:37

    You have two options:

    1. Reset your mobile browser's history because your browser's cache reads the old source.
    2. Change the name of your source file in the desktop and refresh your page again.
    0 讨论(0)
  • 2021-01-13 08:55

    Answer: the reason it wasn't working on iOS Safari is because in my js page I was using ES6, specifically 'let' which is [not supported currently][1]. Changed to ES5 and the issue disappeared.

    $('body').on('click', '.dashboard_leftNav_category a', function() {
          var link = $(this).attr('showSection'); //changed from let link
          var show = $('[section="'+link+'"]');
          $('[section]').hide();
          $('body').find(show).fadeIn();
          $('html,body').scrollTop(0);
        });
    
    0 讨论(0)
  • 2021-01-13 08:55

    This should help you. Instead of binding it to the body element, bind the event to the document.

    $(document).on('click touchstart', '.myContainer', function() {
    
          $(this).toggleClass('myContainer-unselected').toggleClass('myContainer-selected');
        });
    

    Also try changing adding the following style to myContainer class

    cursor : pointer;
    
    0 讨论(0)
提交回复
热议问题