You can try it like this:
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
and let jQuery do the rest for you:
if( isMobile.any() ){
$('a').attr('href', 'tel:1323456458897');
}
SIDENOTE:
To specify which <a>
should be affected, give your <a>
an id and do it like this:
if (isMobile.any()) {
$('a#phonea').attr('href', 'tel: 4515715151456');
}
I use it like this, to disable the complete link when not on mobile: (id phone is in my case a <li>
element
else {
$('#phone').html('<i class="fa fa-phone"></i> Phone: 4515415411818');
}
I've setup a little fiddle with a button to show: http://jsfiddle.net/rp8ma5oe/