如何在 Web 应用程序中检测 tel: uri 方案的可用性?
我希望使用 tel: uri 方案 (rfc3966) 使电话号码可在 Web 应用程序中的移动设备上链接,但我不想将它们链接到无法处理 tel: 方案的设备上 - 桌面,或没有电话功能的移动设备(即 iPad!)
有什么方法可以检测到这一点吗?如果可能的话,我希望避免用户代理嗅探。
iPhone 似乎有一个 canOpenURL 函数,应用程序可以使用它来测试它,但我想从 Javascript 获得相同的行为。
I'm looking to use the tel: uri scheme (rfc3966) to make phone numbers linkable on mobile devices in a web application, but I'd prefer to not link them on devices that can't handle the tel: scheme - desktops, or mobile devices without phone functionality (i.e. iPads!)
Is there some way to detect this? I'd prefer to avoid user agent sniffing, if possible.
The iPhone seems to have a canOpenURL function that apps can use to test this, but I'd like to get the same behaviour from Javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有标准方法可以检测浏览器对 tel URI 方案的支持。
但是,您可以使用用户代理嗅探库,例如优秀的 WURFL 库,它可以检测此功能。
There's no standard way of detecting browser support for the tel URI scheme.
You can however user-agent sniffing library, such as the excellent WURFL library which can detect this feature.
iPhone会自动识别一般文本是否为电话号码格式,并将其转换为可点击的链接。您无需付出任何努力。
即,如果您的网站上有文本“+61 (0)7 3000 0000”,iPhone 会知道这是一个数字,并将其设为链接。
The iPhone will automatically pick up whether general text is in phone number format and turn it into a clickable link. No effort required on your side.
ie If you have text "+61 (0)7 3000 0000" on your site the iPhone will know it's a number and make it a link.
MobileESP 项目具有适用于多种服务器端语言的 API 以及客户端 JavaScript API。
哦!而且它是免费和开源的(我相信 Apache 许可证)
The MobileESP project has APIs for several server-side languages, as well as a client-side JavaScript API.
Oh! and it's free and open-source (Apache license I believe)