9

Is it possible to check if a phone number hyperlink is supported by a browser? EG: Check if

<a href="tel:555555555">Call us on 555555555</a> 

will work.

I'm trying to avoid the "Cannot open page. Safari cannot open the page because the address is invalid." type messages on things like iPod/iPad etc.

Thanks.

Strontium_99
  • 1,771
  • 6
  • 31
  • 52
  • "check" in what sense? – painotpi May 29 '13 at 09:38
  • Don't think so. Skype handles them for instance (I think) if it's installed with plugin, so it's not that clear cut. – Rich Bradshaw May 29 '13 at 09:38
  • possible duplicate of http://stackoverflow.com/questions/13675535 –  May 29 '13 at 09:38
  • if its supported at all, it's likely to be a browser plugin rather than native support, so I doubt the browser will tell you anything helpful about that. – Spudley May 29 '13 at 09:38
  • what do you mean by "phone number hyperlink"? on click call or else... – Jai May 29 '13 at 09:39
  • So is this a specific mobile application? If so, the `href="tel:"` is supported on almost every browser. – Alex May 29 '13 at 09:42
  • Also this is potentially a dupe of this question - http://stackoverflow.com/questions/12141909/detecting-html-a-click-to-call-support-in-javascript – Alex May 29 '13 at 09:43
  • @AlexThomas No. It's not a mobile application, it's a responsive site so can be hit by pretty much any borwser out there. – Strontium_99 May 29 '13 at 09:49
  • @user1001421 see [this question](http://stackoverflow.com/questions/12141909/detecting-html-a-click-to-call-support-in-javascript), this should help with the *checking* – Alex May 29 '13 at 09:54
  • @AlexThomas Thanks for the response, but it doesn't really help. That seems to just check if the device is a Nokia and changes tel: to wtai://wp/mc; – Strontium_99 May 29 '13 at 09:59
  • 1
    @user1001421 - True, but it shows that you could detect if its a mobile, and if it's not, remove the `tel:` – Alex May 29 '13 at 10:06
  • @AlexThomas Hmmmmmm. Good point. I'll have a play. Thanks – Strontium_99 May 29 '13 at 10:10
  • 1
    I dont know if it is relevant or not... but would the browser think that 'tel' is a protocol? if you want to check if a protocol is accepted by the browser : http://www.rajeshsegu.com/2012/09/browser-detect-custom-protocols/. I dont know if it could help or even work here – mlwacosmos May 29 '13 at 10:29
  • @mlwacosmos Thanks. I'll check that out. Looks promising. – Strontium_99 May 29 '13 at 11:30
  • possible duplicate of [How to launch apps (facebook/twitter/etc) from mobile browser but fall back to hyperlink if the app isn't installed](http://stackoverflow.com/questions/13675535/how-to-launch-apps-facebook-twitter-etc-from-mobile-browser-but-fall-back-to-h) – Benjamin Gruenbaum May 30 '13 at 01:42
  • try this http://stackoverflow.com/questions/17345177/use-jquery-to-detect-whether-a-device-can-make-telephone-calls-supports-tel or you can check the feature with something like modernizr – keypaul Sep 12 '14 at 07:41

1 Answers1

3

On desktop Skype uses the "callto:" spec instead of "tel:"

I think you could use css for this.

Just add some @media rules:

.telClass { display: none; }
.callToClass { display: block; } 

@media only screen and (max-device-width: 480px) {
    .tel-class { display: block; }
    .call-to-class { display: none; }
}

Then you could define two elements in html:

<a href="tel:555555555" class="tel-class">Call us on 555555555</a> 
<a href="callto:555555555" class="call-to-class">Call us on 555555555</a> 

For a more complex code you could add some javascript code to check if the device is a handheld one:

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
   var callToArray = document.getElementsByClassName('call-to-class');
   callToArray.forEach(function(c) {
      c.parentElement.removeChild(c);
   });
}

Also there is a nice answer here by ghepting on how to to detect if skype is installed or not.

Community
  • 1
  • 1
Teo
  • 614
  • 1
  • 4
  • 13