Click to call html
Solution 1:
tl;dr What to do in modern (2018) times? Assume tel:
is supported, use it and forget about anything else.
The tel:
URI scheme RFC5431 (as well as sms:
but also feed:
, maps:
, youtube:
and others) is handled by protocol handlers (as mailto:
and http:
are).
They're unrelated to HTML5 specification (it has been out there from 90s and documented first time back in 2k with RFC2806) then you can't check for their support using tools as modernizr. A protocol handler may be installed by an application (for example Skype installs a callto:
protocol handler with same meaning and behaviour of tel:
but it's not a standard), natively supported by browser or installed (with some limitations) by website itself.
What HTML5 added is support for installing custom web based protocol handlers (with registerProtocolHandler()
and related functions) simplifying also the check for their support through isProtocolHandlerRegistered()
function.
There is some easy ways to determine if there is an handler or not:" How to detect browser's protocol handlers?).
In general what I suggest is:
- If you're running on a mobile device then you can safely assume
tel:
is supported (yes, it's not true for very old devices but IMO you can ignore them). - If JS isn't active then do nothing.
- If you're running on desktop browsers then you can use one of the techniques in the linked post to determine if it's supported.
- If
tel:
isn't supported then change links to usecallto:
and repeat check desctibed in 3. - If
tel:
andcallto:
aren't supported (or - in a desktop browser - you can't detect their support) then simply remove that link replacing URL inhref
withjavascript:void(0)
and (if number isn't repeated in text span) putting, telephone number intitle
. Here HTML5 microdata won't help users (just search engines). Note that newer versions of Skype handle bothcallto:
andtel:
.
Please note that (at least on latest Windows versions) there is always a - fake - registered protocol handler called App Picker (that annoying window that let you choose with which application you want to open an unknown file). This may vanish your tests so if you don't want to handle Windows environment as a special case you can simplify this process as:
- If you're running on a mobile device then assume
tel:
is supported. - If you're running on desktop
then replacethen droptel:
withcallto:
.tel:
or leave it as is (assuming there are good chances Skype is installed).
Solution 2:
Use this,
<a href="tel:XXX-XXX-XXXX">XXX-XXX-XXXX</a>