Phonegap 2.4.0 with Android 4.2 - strange double click behaviour

前端 未结 5 1057
暖寄归人
暖寄归人 2020-12-30 08:03

I\'m using phonegap 2.4.0 to create an Android and iOS App.

Now I recognized that the onclick event in links is fired twice inside the Android App using Android 4.2.

5条回答
  •  半阙折子戏
    2020-12-30 08:32

    I think the reason of these double/multiple clicks are malfunctioning hardware accelerations, I'm experiencing simultaneous clicks + propagation's, propagation's are easy to prevent, however since third argument of addEventListener isn't respected in my case, I can't prevent double click even with the previously answered code, here is what I ended up using

    function cw(event) // click wall
    { try {
        click_time_cw = (new Date()).getTime();
        if (click_time_cw && (click_time_cw - last_click_time_cw) < 350) {
            event.stopImmediatePropagation();
            event.preventDefault();
            add_log('prevented misclick [CW] '+(click_time_cw - last_click_time_cw));
            return true;
        }
        last_click_time_cw = click_time_cw;
        event.stopImmediatePropagation();
        event.stopPropagation();
        return false;
    } catch(e){ add_alert(e,"stpr"); } }
    

    you also have to initialize last_click_time_cw=(new Date()).getTime() somewhere

    this is an example onclick:

    
    

    it might seem like a lot of work and an unpleasant/ugly fix, but click problems have been haunting me for months, it seems like this is what I should've done from the begining

提交回复
热议问题