一个href电话和标准浏览器

时间:2013-01-22 10:28:21

标签: php jquery html anchor tel

我的项目需要<a href="tel:123456">超过电话号码(123456不是数字)但是这会因为无法解释tel:位而导致移动浏览器以外的所有内容出现问题。

我尝试使用jQuery在浏览器宽度<1000px时添加href attr,但这是一种非常不可靠的方法(平板电脑也具有有限的分辨率)。

如何克服这一点的任何想法将不胜感激。我正在使用PHP,jQuery和JavaScript。

4 个答案:

答案 0 :(得分:3)

如果是移动代理,请使用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';
        }
   ?>

答案 1 :(得分:2)

由于您使用的是PHP,我可以推荐php-mobile-detect类。您可以满足各个设备/操作系统/浏览器的需求,或者只使用isMobile()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;?&gt;无论我需要它,它都是一种享受!通过使用PHP而不是javascript,这意味着检测是在服务器端完成的,因此最终用户的下载量较少(如jQuery和额外的脚本)。

设备库经常更新,因此值得每隔一段时间检查GitHub page

答案 2 :(得分:1)

您想要检测用户是否拥有移动浏览器? 这可能会有所帮助:

http://jquerybyexample.blogspot.com/2012/03/detect-mobile-browsers-using-jquery.html

答案 3 :(得分:-1)

请尝试以下方法之一:

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';
    }
 ?>
相关问题