Pregunta

I'd like to know if this will work on touch devices. Can somebody offer a better solution for touch devices ? Would it be better to use JQuery mobile?

Note: When I ask "will it work" I'm not talking about the sourcecode but rather about the method how to handle touch devices. I have tested it on my tablet it works, I'm just not sure about every other device. Am I missing something ?

var isTouch = "ontouchstart" in document.documentElement;
var Event;

if(isTouch == true ) {
  Event = "tap";
  console.log("is touch devise");
} else {
 Event = "click";
  console.log("is click devise");
}


$(function () {
    $('#what_ever').on(Event, function() {
        $(this).do_something();
    });
});

What kind of answer I'm looking for?

Nope you are wrong, it's better to use this link or Yep should be ok, you can handle all devices with it.

Thanks for your time

¿Fue útil?

Solución

There's no need to register a different event handler. Click will work just fine. Add Fastclick and you're good to go with default click handler.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top