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

前端 未结 24 2042
终归单人心
终归单人心 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:04

    It is generally a better idea to detect if the mouseover function is supported rather than detecting the OS/browser type. You can do that simply by the following:

    if (element.mouseover) {
        //Supports the mouseover event
    }
    

    Be sure that you don't do the following:

    if (element.mouseover()) {
        // Supports the mouseover event
    }
    

    The latter would actually call the method, rather than check for its existence.

    You can read up more here: http://www.quirksmode.org/js/support.html

提交回复
热议问题