Detecting that the browser has no mouse and is touch-only

前端 未结 24 1986
终归单人心
终归单人心 2020-11-27 09:35

I\'m developing a webapp (not a website with pages of interesting text) with a very different interface for touch (your finger hides the screen when you click) and mouse (re

24条回答
  •  眼角桃花
    2020-11-27 10:12

    Why don't you just detect if it has the ability to sense touches and/or to react to mouse movements?

    // This will also return false on
    // touch-enabled browsers like Chrome
    function has_touch() {
      return !!('ontouchstart' in window);
    }
    
    function has_mouse() {
      return !!('onmousemove' in window);
    }
    

提交回复
热议问题