您可以使用JavaScript检测设备是否具有电话功能(例如,它可以拨打语音电话/短信)吗? [英] Can you detect whether a device has phone capabilities (e.g. it can make voice calls/SMS) with JavaScript?
问题描述
有没有办法检测移动设备是否能够拨打语音电话/短信?
Is there any way to detect whether a mobile device is capable of making voice calls / SMS messages?
这在申请电话时非常重要:
和短信:
网页中的链接。仅仅检测手机是不够的,因为平板电脑无法拨打电话,iTouch无法拨打电话等。
This is important when applying tel:
and sms:
links in a web page. It is not enough to merely detect mobile, since tablets can't make calls, iTouch can't make calls, etc.
我对移动检测黑客不感兴趣使用设备大小,UA字符串检测等。我想使用功能检测来确定设备是否能够进行语音呼叫/ SMS短信。我喜欢通用的解决方案,但我主要对iOS / Android感兴趣。
I'm not interested in mobile detection hacks using device size, UA string detection, etc. I want to use feature detection to determine if the device is capable of voice calls / SMS text messaging. I'd love a universal solution, but am mainly interested in iOS / Android.
推荐答案
我还没有看到一个明显的方式来看那个短信:
和 tel:
链接得到特殊待遇。
I havent seen an obvious way to see that sms:
and tel:
links get special treatment.
更新:下面的@janogosteve已确认目前没有可靠的功能检测。这看起来无法察觉。
Update: @janogosteve below has confirmed there is currently no reliable feature detect. This looks undetectable.
这是检查此功能检测的综合方法。 (阅读下面的jangosteve评论!)
Here's a comprehensive way to check this feature detect. (Read jangosteve comment below!)
- 制作包含其中两个链接和常规http链接的测试页
- 抓取元素,然后遍历所有属性,将其全部复制到对象..
- 还
getComputedStyle
info关于它们的一堆细节并将其扔进一个对象中 -
JSON.stringify
(这些东西让你可以处理稍后))
- make a test page with two of those links and a regular http link
- grab the elements and then traverse all their properties, copy it all over to an object..
- also
getComputedStyle
info for a bunch of details on them and throw that into an object as well JSON.stringify
( that stuff so you can deal with it later on)
在iOS设备和桌面Safari / Chrome中执行以上操作
Do the above on an iOS device and in desktop Safari/Chrome
然后 JSON.parse
他们回到对象...并使用 https://github.com/NV/objectDiff.js ,看看你是否能发现任何差异。
Then JSON.parse
them back into objects... and use https://github.com/NV/objectDiff.js to see if you can spot any differences at all.
这篇关于您可以使用JavaScript检测设备是否具有电话功能(例如,它可以拨打语音电话/短信)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!