Use onclick and ontouchstart

Asked

Viewed 448 times

2

I have this div:

<div onclick="funcao('')">

And in Iphone (mainly the 6) the onclick does not run very well. I saw that the ideal is to use the ontouchstart, but when I put both of the error, because he thinks it was clicked 2 times.

What to do?

  • What do you mean, "don’t run very well"?

  • There’s a time when he takes the onclick, there’s a time when....

1 answer

3

What I usually do is like this:

var appEvents = {
    down: 'ontouchstart' in window ? 'touchstart' : 'click' /* ou mousedown */,
    move: 'ontouchmove' in window ? 'touchmove' : 'mousemove',
    up: 'ontouchend' in window ? 'touchend' : 'mouseup'
    // e outros que precises
}

and then use

el.addEventListener(appEvents.down, function(){

so it detects if it is in browser environment and uses the click or mobile environment and uses the touchstart

  • Thanks Sergio, is that the site is already rolling, and ta all inline the onclick.... I would have to see a way to change all onclick to ontouchstart

Browser other questions tagged

You are not signed in. Login or sign up in order to post.