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
Written by emi420
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#