Last Updated: February 25, 2016
·
2.11K
· emi420

How to fix Android double click/touch

I use Zepto for one mobile project and this was my solution for fix this behavior on Android devices.

Detect touch support:

if ( !!('ontouchstart' in window) ) {

Wrapper for the Zepto function:

$.fn._on = $.fn.on;
$.fn.on = function(event, selector, data, callback, one) {

Remove 'click' event that causes the problem:

if (event.indexOf("click") > -1) {
    event = event.replace("click","");
}

And return scope:

return $.fn._on.call(this, event, selector, data, callback, one);

Full code:

if ( !!('ontouchstart' in window) ) {
    $.fn._on = $.fn.on;
    $.fn.on = function(event, selector, data, callback, one) {
        if (event.indexOf("click") > -1) {
            event = event.replace("click","");
        }
        return $.fn._on.call(this, event, selector, data, callback, one);
    };
}

https://github.com/emi420/Mootor/blob/master/source/js/clickfix.js

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside