Don't fire onclick for touches - Javascript

361 Views Asked by At

I'm writing an HTML5 app based on canvas with mouse and touch support. For mouse event I'm using this function:

canvas.onmousedown = function (e) { .... }

And this for touch events:

canvas.ontouchstart = function (e) { .... }

Click events are working fine, but when on touch input both events are fired.

Is there a way to prevent firing the click event on touch input?

1

There are 1 best solutions below

0
On BEST ANSWER

Try registering onmousedown event only when touchstart event is not available.

if(!canvas.ontouchstart){
  canvas.onmousedown = function (e) { .... }
}