Detecting HTML <a> click-to-call support in Javascript

爷,独闯天下 提交于 2019-11-30 06:38:28

问题


There are two ways to have click-to-call links in HTML

  • <a href="wtai://wp/mc;+1800229933</a> WTAI style (Nokia, others)

  • <a href="tel:+1-800-275-2273">Call Apple Customer Support at 1-800-275-2273</a>. TEL style (Apple)

How one can

  • detect which format is supported by current user agent in Javascript?

  • Is it possible to do the detection without relying the user agent string

More info

  • http://www.mobilexweb.com/blog/click-to-call-links-mobile-browsers

  • http://www.raizlabs.com/blog/2007/07/02/iphone-telephone-hyperlinks/


回答1:


Max Firtman has a great article on how to create click-to-call links for mobile browsers. He states that the tel: protocol is supported by almost every mobile device, including: Safari on iOS, Android Browser, webOS Browser, Symbian browser, Internet Explorer, Opera Mini and low-end devices browsers.

Because of the wide support of the tel: protocol, I would suggest just use the tel: protocol. To support Nokia I would check if the navigator.userAgent contains Nokia footprint. If so, replace tel: to wtai://wp/mc;

If you can use jQuery, the Javascript could look something like:

if (/(Series60|Nokia)/i.test(navigator.userAgent)){
  $("a[href^='tel:']").each(function(){
    this.href = this.href.replace("tel:", "wtai://wp/mc;");
  });
}


来源:https://stackoverflow.com/questions/12141909/detecting-html-a-click-to-call-support-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!