Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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: 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.

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.

like image 751
Jon Raasch Avatar asked Aug 03 '11 18:08

Jon Raasch


People also ask

How do I make a phone call using Javascript?

You can simply add an onclick handler to your <tr> tag, then call window. open("tel:+1800229933"); . This should be marked as the correct answer as this is an implementation done without the <a /> anchor tag as asked in the question.

How do you link a phone call?

Settings. Under "Account," tap Devices and numbers. Tap New linked number. Enter the phone number to link.


1 Answers

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.

like image 130
Paul Irish Avatar answered Sep 20 '22 18:09

Paul Irish