Can you detect whether a device has phone capabilities (e.g. it can make voice calls/SMS) with JavaScript?

前端 未结 2 427
野性不改
野性不改 2020-12-25 12:28

Is there any way to detect whether a mobile device is capable of making voice calls / SMS messages?

This is important when applying tel: and sms:<

2条回答
  •  萌比男神i
    2020-12-25 13:00

    I havent seen an obvious way to see that sms: and tel: links get special treatment.

    Update: @janogosteve below has confirmed there is currently no reliable feature detect. This looks undetectable.


    Here's a comprehensive way to check this feature detect. (Read jangosteve comment below!)

    • 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)

    Do the above on an iOS device and in desktop Safari/Chrome

    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.

提交回复
热议问题