문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top