使用jQuery检测设备是否可以拨打电话(支持“tel://"协议) [英] Use jQuery to detect whether a device can make telephone calls (supports "tel://" protocol)
问题描述
在我的网站上,我有几个这样的链接:
我想使用 jQuery(或其他方法)来确定设备是否支持拨打电话/使用 tel://协议.世界上有这种方法吗?
我想使用某种方法来启用或禁用链接,因为当在桌面上单击时,我们会进入一个页面,例如Firefox 不知道如何打开此地址,因为协议 (tel) 与任何程序."
目前,我正在嗅探用户代理并检测它是否是移动设备.但是,有更好/更准确的方法吗?类似于 jQuery 的 $.support.xx
?
if ( (/iPhone|iPod|iPad|Android|BlackBerry/).test(navigator.userAgent) != true ){$(".call").attr("href", "#");}
我不确定 Android 或 BlackBerry,但 iOS 会自动提取电话号码并像这样包装它们:<a href="tel:xxx">xxx</a>
...所以你可以有一个隐藏的
var isTelephone = $("a[href*='tel:']").length >0;
这可能会也可能不会移植到其他平台,您必须尝试一下.
In my website, I have several links like so:
<a href="tel://+12181112222" class="call">218.111.2222</a>
I want to use jQuery (or other method) to determine whether the device supports making calls / using the tel:// protocol. Does such a method exist in the world?
I want to use some method for enabling or disabling the links, because when clicked on desktop we come to a page like "Firefox doesn't know how to open this address, because the protocol (tel) isn't associated with any program."
Currently, I am sniffing the user agent and detecting if it is a mobile device. But, is there a better/accurate way? Something like jQuery's $.support.xx
?
if ( (/iPhone|iPod|iPad|Android|BlackBerry/).test(navigator.userAgent) != true ){
$(".call").attr("href", "#");
}
I'm not sure about Android or BlackBerry, but iOS will automatically pick up telephone numbers and wrap them like so: <a href="tel:xxx">xxx</a>
...so you could have a hidden <div>
somewhere that contains a phone number like 1-800-555-5555, then, on page load do something like this:
var isTelephone = $("a[href*='tel:']").length > 0;
This may or may not be portable to other platforms, you'll have to try it out.
这篇关于使用jQuery检测设备是否可以拨打电话(支持“tel://"协议)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!