简体   繁体   English

检查是否<a href=“tel:5555555”>支持</a>

[英]Check if <a href=“tel:5555555”> is supported

Is it possible to check if a phone number hyperlink is supported by a browser? 是否可以检查浏览器是否支持电话号码超链接? EG: Check if EG:检查是否

<a href="tel:555555555">Call us on 555555555</a> 

will work. 将工作。

I'm trying to avoid the "Cannot open page. Safari cannot open the page because the address is invalid." 我试图避免“无法打开页面.Safari无法打开页面,因为地址无效。” type messages on things like iPod/iPad etc. 输入iPod / iPad等信息。

Thanks. 谢谢。

On desktop Skype uses the "callto:" spec instead of "tel:" 在桌面上Skype使用“callto:”规范而不是“tel:”

I think you could use css for this. 我想你可以用css来做这件事。

Just add some @media rules: 只需添加一些@media规则:

.telClass { display: none; }
.callToClass { display: block; } 

@media only screen and (max-device-width: 480px) {
    .tel-class { display: block; }
    .call-to-class { display: none; }
}

Then you could define two elements in html: 然后你可以在html中定义两个元素:

<a href="tel:555555555" class="tel-class">Call us on 555555555</a> 
<a href="callto:555555555" class="call-to-class">Call us on 555555555</a> 

For a more complex code you could add some javascript code to check if the device is a handheld one: 对于更复杂的代码,您可以添加一些JavaScript代码来检查设备是否为手持设备:

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
   var callToArray = document.getElementsByClassName('call-to-class');
   callToArray.forEach(function(c) {
      c.parentElement.removeChild(c);
   });
}

Also there is a nice answer here by ghepting on how to to detect if skype is installed or not. 也有一个很好的答案在这里通过ghepting如何,如果安装或没有Skype的检测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM