使用jQuery检测设备是否可以拨打电话(支持“tel://”协议) [英] Use jQuery to detect whether a device can make telephone calls (supports "tel://" protocol)

查看:238
本文介绍了使用jQuery检测设备是否可以拨打电话(支持“tel://”协议)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我有几个这样的链接:

In my website, I have several links like so:

< a href =tel:// + 12181112222class = call> 218.111.2222< / a>

我想使用jQuery(或其他方法)来确定设备是否支持拨打电话/使用tel://协议。世界上是否存在这样的方法?

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?

我想使用某种方法启用或禁用链接,因为当点击桌面时我们会看到像Firefox这样的页面不知道如何打开这个地址,因为协议(tel)与任何程序都没有关联。

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."

目前,我正在嗅探用户代理并检测如果它是移动设备。但是,有更好/准确的方法吗?像jQuery的 $ .support.xx

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", "#");
}


推荐答案

我不确定Android或BlackBerry,但iOS会自动接收电话号码并将其换行:< a href =tel:xxx> xxx< / a> .. .so你可以有一个隐藏的< div> 某处包含一个电话号码,如1-800-555-5555,然后,在页面加载时做这样的事情:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆