onclick and ontouchstart simultaneously

后端 未结 6 1933
花落未央
花落未央 2021-02-08 21:23

I have an ontouchstart event triggered on my mobile view, its linked to this:

function mobileLinksShow() {
    document.querySelector(\'.mobile-head         


        
6条回答
  •  面向向阳花
    2021-02-08 21:42

    Found a work around by testing the browser type and removing the onclick accordingly:

    function removeMobileOnclick() {
        if(isMobile()) {
            document.querySelector('.mobile-head-bar-left').onclick  = '';
        }
    }
    
    function isMobile() {
        if (navigator.userAgent.match(/Android/i)
                || navigator.userAgent.match(/iPhone/i)
                || navigator.userAgent.match(/iPad/i)
                || navigator.userAgent.match(/iPod/i)
                || navigator.userAgent.match(/BlackBerry/i)
                || navigator.userAgent.match(/Windows Phone/i)
                || navigator.userAgent.match(/Opera Mini/i)
                || navigator.userAgent.match(/IEMobile/i)
                ) {
            return true;
        }
    }
    window.addEventListener('load', removeMobileOnclick);
    

    This way you can have both onclick and ontouchstart not interfering

    isMobile function taken from Detecting mobile devices and the webOS part removed as this saw the desktop browser as mobile.

提交回复
热议问题