Use jQuery to detect whether a device can make telephone calls (supports “tel://” protocol)

前端 未结 4 2105
天命终不由人
天命终不由人 2020-11-28 14:37

In my website, I have several links like so:

218.111.2222

I want to use jQuery (or

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 15:01

    I'm using the following to detect its PROBABLY a phone before enhancing a non link element that into a tel link:

    var probablyPhone = (
        (/iphone|android|ie|blackberry|fennec/).test
         (navigator.userAgent.toLowerCase())
         && 'ontouchstart' in document.documentElement
      );
    

    I exclude ipod|ipad because I know they are not phones

    The key point here is PROBABLY It will of course return true an some tablet devices, but this enough for my purposes on a non phone touch device the link would just fail anyway - I mostly just want to exclude desktop hence the touch event detect. I suppose also checking device width would narrow it down too but ultimately there is no guaranteed way to detect a mobile device that is capable of phone calls that I've found.

提交回复
热议问题