Skip to content

Instantly share code, notes, and snippets.

@antlis
Created November 28, 2017 15:43
Show Gist options
  • Save antlis/6b9492b88a4f0a0fb3ea1dd84f53eb18 to your computer and use it in GitHub Desktop.
Save antlis/6b9492b88a4f0a0fb3ea1dd84f53eb18 to your computer and use it in GitHub Desktop.
tel links callto fallback
$('a[href^=\'tel:\']').each(function() {
var target = 'call-' + this.href.replace(/[^a-z0-9]*/gi, '');
var link = this;
// load in iframe to supress potential errors when protocol is not available
$('body').append('<iframe name="' + target + '" style="display: none"></iframe>');
link.target = target;
// replace tel with callto on desktop browsers for skype fallback
if (!navigator.userAgent.match(/(mobile)/gi)) {
link.href = link.href.replace(/^tel:/, 'callto:');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment