Swappable callto: and tel: for Skype & iPhone

Posted Thursday April 29, 2010 and modified Monday May 3, 2010
Filed Under: , , , , ,

Marking up a telephone number to use Skype’s callto: except when User Agent is iPhone uses tel:.

Javascript

<script language="javascript">
window.onload = function () {
  if (navigator.userAgent.match (/iPhone/i)) {
    var a = document.getElementsByTagName ("a");
    for (var i = 0; i < a.length; i++) {
      if (a[i].getAttribute ('href').search (/callto:/i) === 0) {
        a[i].setAttribute ('href', a[i].getAttribute ('href').replace (/^callto:/, "tel:"));
      }
    }
  }
};
</script>

The precending chunk of Javascript in the head of a document will swap out callto: for tel: in the following HTML.

HTML

<a href="callto:15035555555">+1 (503) 555 5555</a>

This leaves you with a hyper-linked phone number which depends on the user to have Skype installed on their machine so if you’d prefer to not confuse those without Skype by tempting them to click the number then you might stick a Skype icon along side the link.

User Agents other than iPhone will recognize the tel: protocol so the Javascript above could be expanded to involve more User Agents.

Filed Under: , , , , ,
· Tweet!

Comments

Add your comment. Preview then Submit.


Hidden


Textile Help

 
Trusted Payments
Send a text to 646.836.9557 (VENMO):
Pay whaleen