How to check browser for touchstart support using JS/jQuery?

前端 未结 4 1301
一生所求
一生所求 2020-11-28 05:12

In an attempt to follow best practices, we\'re trying to use the proper JavaScript/jQuery events according to what device you are using. For example, we\'re building a mobil

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 05:44

    You can detect if the event is supported by:

    if ('ontouchstart' in document.documentElement) {
      //...
    }
    

    Give a look to this article:

    • Detecting event support without browser sniffing

    The isEventSupported function published there, is really good at detecting a wide variety of events, and it's cross-browser.

提交回复
热议问题