18

So if you want to link to a phone number you would do something like

<a href="tel:18005555555">Click to Call</a>

This is used commonly on mobile websites and is gaining traction on desktop sites as well (largely thanks to Skype I think.) However some computers/devices aren't able to support it. Is there a way to tell if a user is able to handle tel: links?

Solution can be either server side or client side but I would imagine it would need to be client side.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
Andrew G. Johnson
  • 26,603
  • 30
  • 91
  • 135
  • 1
    I find this very amusing: I was investigating *exactly* this issue (and for `geo:` links) just one hour ago. – Chris Morgan Jun 22 '13 at 14:21
  • 1
    One "discussion" (one-sided!) on the topic that I found was http://www.sitepoint.com/forums/showthread.php?610038-Detecting-Browser-Support-For-Speciic-URI-Schemes-(geo-tel-etc-). The technique there doesn't work for me in Chrome on Ubuntu; Chrome tries to pass it to `xdg-open` when clicked and the XMLHttpRequest doesn't fail. – Chris Morgan Jun 22 '13 at 14:23
  • @ChrisMorgan - Ya that solution seems buggy at best, this is unfortunately a tough issue to Google – Andrew G. Johnson Jun 22 '13 at 14:31
  • 1
    @ŠimeVidas - that seems to be for not – Andrew G. Johnson Jun 22 '13 at 14:32
  • 2
    I'd suggest closing this as a duplicate of [a href tel and standard browsers](http://stackoverflow.com/questions/14456387/a-href-tel-and-standard-browsers), but I couldn't bear to do that to a good question in favour of a question which heads in the wrong direction, with answers purely to do with detecting mobile browsers... fortunately, the question there can be construed as asking how to detect mobile browsers rather than `tel:` URI scheme support, so I am happy to not mark it as a duplicate. – Chris Morgan Jun 22 '13 at 14:44
  • @ChrisMorgan - Appreciated, that restraint is missing and needed in a big way these days on StackOverflow in my opinion. I saw that one too in the related questions list and actually considered downvoting it and/or doing a massive edit of it since as you say they end up going in a completely bizarre direction that doesn't actually answer the question at all. – Andrew G. Johnson Jun 22 '13 at 14:46
  • @AndrewG.Johnson: I'm also biased by really wanting a good answer myself! – Chris Morgan Jun 22 '13 at 14:47
  • Tried the solution in [How to launch apps (facebook/twitter/etc) from mobile browser but fall back to hyperlink if the app isn't installed](http://stackoverflow.com/a/13675901), didn't work at all in Firefox, so it didn't satisfy me at all. – Chris Morgan Jun 22 '13 at 15:04
  • @Sergio: sorry, but that's absolutely no use. We're talking browser, not native. People also forget that it's not just mobile browsers that can support `tel:`, `geo:`, etc. Other environments can, too. – Chris Morgan Jun 22 '13 at 16:13
  • @ChrisMorgan, true. Removed. – Sergio Jun 22 '13 at 16:16
  • See this link to get better answer http://stackoverflow.com/questions/1164004/how-to-mark-up-phone-numbers – zeenfaiz Jul 09 '13 at 11:03
  • @zeenfaiz: that doesn't offer any solution to the question here. – Chris Morgan Jul 13 '13 at 14:13
  • How the Windows OS knows which application to trigger for which _protocol_ is by checking for the entry in the registry HKLM. It is called the URI Scheme as mentioned by the [Microsoft MSDN](https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx). But client side scripting in web development do not allow you to read registry entries for security reasons, Therefore your closest work around would be to check for the user's [browser user agent](http://www.w3schools.com/jsref/prop_nav_useragent.asp) to guess which device is being used..(unless [Java Web](https://jna.java.net/) is allowed) – Ahs N Sep 04 '15 at 07:08
  • Did you check the answers in here http://stackoverflow.com/questions/2872090/how-to-check-if-a-custom-protocol-supported this is basically the generalized version of your question. – Niki van Stein Sep 22 '15 at 19:28

6 Answers6

2

DeviceAtlas and Wurfl can get you some of this information, but as many have pointed out, there’s really no truly reliable way to detect a device’s ability to make a call. After all, someone might be on desktop, but capable of making a call from it based on the software they have installed (or even their OS capabilities).

In the interest of providing the best experience, you should include tel: links. That will give everyone the opportunity to dial the number if they can handle it. You could use CSS to make it look less link-like to reduce potential confusion for non tel: supporting browsers/OSes. Users who want to call the number will select it or touch it anyway (in hopes of copying the number) and will either activate the link (in touch scenarios) or see the hand (in mousing scenarios), helping them more quickly achieve their goal.

As a bit of an aside, setting white-space: nowrap on tel: links is always a good idea too :-) That will keep numbers on a single line so the hyphens don’t allow it to break.

a[href^=tel:] { white-space: nowrap; }
Aaron Gustafson
  • 602
  • 6
  • 11
0

Just a thought, but if you enter the below header information

<meta name="format-detection" content="telephone=yes">

You will be able to enter phone numbers without the tel: prefix (or even an anchor) and the browser will auto-convert them to clickable phone links.

I think this may be more reliable than feature or agent detection.

mrmrw
  • 87
  • 7
  • I don't really like this way of doing it... it's not proper data, then—and how widely is it supported? For myself, I also want it for `geo:` links, so this isn't a general solution. Thanks for the thought, though; it may well be useful for some situations. – Chris Morgan Jun 25 '13 at 00:03
0

I know I'm coming along almost 10 years later, but I looked into this issue for tailoring the UI in one of my web apps and ultimately the answer that I settled on was a toggle option on the main user menu:

✔ This device is a phone

When the user toggles this setting on or off, the result is stored in the browser's window.localStorage, so that it can be remembered for later sessions.

The exact wording will depend on your application and why you need to know, but at the end of the day the user knows if their device has the ability to make calls, whereas without asking them, the best we can do is guess.

Grant McLean
  • 6,898
  • 1
  • 21
  • 37
-1

As far as I can tell there doesn't seem to be a good reliable way of doing this. It depends on what software is installed besides the browser and as such I don't think it would be exposed to a webpage (otherwise you can use it to check if the user has certain software installed, especially with application specific links like itunes or visual studio).

EDIT: As pointed out in the comments firefox does try to navigate and will instead show an error page show the below solution won't work for firefox.

An alternative to this is to simply handle someone clicking on it and it not working decently. Testing with chrome it seems the browser simply does nothing if the protocol is not recognized so you could just add an onclick that takes the part after tel: and transform click to call into the actual number. So clicking on it shows the number if they don't have anything installed which is perhaps a decent compromise?

mirhagk
  • 1,255
  • 3
  • 14
  • 28
  • Firefox at least (stock, desktop) will unload your page, showing an error page as it cannot understand `tel:` links. Chrome also may be able to handle it and you cannot tell whether it has handled it or not. This approach is thus fundamentally unworkable. – Chris Morgan Aug 27 '15 at 07:53
-2

As far as I know detecting what capabilities / applications a user has can be tricky for security reasons, but you can rule some things out and go from there.

You could try see of its a mobile browser which can handle the link, and then if not, see if the other device is capable of using a telephone number, e.g. Skype, and again if not, just display a normal number.

this combines answers from these questions a href tel and standard browsers and Javascript to detect Skype?

<div>
<?php if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) { echo '<div id="tel"><a href="tel:123456">123456</a></div>'; }else{?>
    <script>
            function skype (failureFunction) {
                var $ = jQuery;

                if ($.browser.safari || $.browser.opera) {
                    return true;
                } else if ($.browser.msie) {
                    try {
                        if (new ActiveXObject("Skype.Detection")) return true;
                    } catch(e) { }
                } else {
                    if (typeof(navigator.mimeTypes["application/x-skype"]) == "object") {
                        return true;
                    }
                }
                $('a[href^="skype:"]').click(function() {
                    failureFunction();
                    return false;
                });
                return false;
            }

        jQuery(function($) {
            if (skype()) {
                $('div#tel').html("<a href='skype:123456'>123456</a>");
            } else {    
                $('div#tel').html("<p>123456</p>");
            };
        });
    </script>
    <div id="tel"></div>
    <?}?>

I hope its a step in the right direction for yer

Community
  • 1
  • 1
Rudiger Kidd
  • 498
  • 1
  • 5
  • 23
-3

A client side implementation could be realised using the BrowserDetect script and filter the user's browser properties with this list: Can i use: URI

var browser = BrowserDetect.browser;
var browserVersion = parseInt(BrowserDetect.version);
var supportsURI = true;

if((browser == 'Firefox' && browserVersion < 2) || (browser == 'Explorer' && browserVersion < 8) || (...)) {
    supportsURI = false;
}

(not tested)

If the browser doesn't support URI-Schemes you can trigger the link and show a lightbox containing the required data (e.g. the phone number).

greg.ms
  • 109
  • 2
  • 11
  • Would that it were that easy. This is a case where the same browser may or may not support the `tel:` scheme, specifically. – Chris Morgan Jul 13 '13 at 14:10