[英]a href tel and standard browsers
我有一个项目,要求在电话号码上输入<a href="tel:123456">
(不是123456),但这会导致无法解释tel:
位,从而导致除移动浏览器以外的所有问题。
当浏览器宽度小于1000px时,我尝试使用jQuery添加href属性,但这是一种非常不可靠的方法(平板电脑的分辨率也有限)。
任何有关如何克服这一点的想法将不胜感激。 我正在使用PHP,jQuery和JavaScript。
使用PHP检测其是否为移动代理: http : //www.000webhost.com/forum/scripts-code-snippets/27404-php-extremely-simple-way-check-if-mobile-browser.html
<?php
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
echo '<a href="tel:123456">';
}else{
echo 'You are not in a mobile';
}
?>
由于您使用的是PHP,因此我建议您使用php-mobile-detect类。 您可以迎合各个设备/操作系统/浏览器的需求,或者简单地使用isMobile()
或isTablet()
作为isTablet()
。
我通常会这样:
include './includes/Mobile_Detect.php';
$detect = new Mobile_Detect;
if ( $detect->isMobile() or $detect->isTablet() ){
$phone='<a href="tel:+12345678910">1-234-567-8910</a>';
} else {
$phone='1-234-567-8910';
}
然后我只要在需要的地方<?php echo $phone
;?>就可以了! 通过使用PHP而不是javascript,这意味着检测是在服务器端完成的,因此最终用户的下载量减少了(例如jQuery和其他脚本)。
设备库经常更新,因此值得经常检查GitHub页面 。
您想检测用户是否具有移动浏览器? 这可能会有所帮助:
http://jquerybyexample.blogspot.com/2012/03/detect-mobile-browsers-using-jquery.html
请尝试以下一种方法:
Syntex:callto
<a href="callto://9566603286">9566603286</a>
<?php
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
echo '<a href="callto://9566603286">9566603286</a>';
}else{
echo 'You are not in a mobile';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.