Philipp Br
Philipp Br

Reputation: 113

Don't fire onclick for touches - Javascript

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?

Upvotes: 2

Views: 372

Answers (1)

vinayakj
vinayakj

Reputation: 5681

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

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

Upvotes: 1

Related Questions