[英]a href tel and standard browsers
I have a project that requires <a href="tel:123456">
over the phone number (123456 is not the number) however this will cause an issue for everything except mobile browsers by being unable to interpret the tel:
bit. 我有一个项目,要求在电话号码上输入
<a href="tel:123456">
(不是123456),但这会导致无法解释tel:
位,从而导致除移动浏览器以外的所有问题。
I have tried to use jQuery to add the href attr when a browser width is <1000px but this is a very unreliable method (tablets also have a limited resolution). 当浏览器宽度小于1000px时,我尝试使用jQuery添加href属性,但这是一种非常不可靠的方法(平板电脑的分辨率也有限)。
Any ideas on how to overcome this would be greatly appreciated. 任何有关如何克服这一点的想法将不胜感激。 I am using PHP, jQuery and JavaScript.
我正在使用PHP,jQuery和JavaScript。
Detect with PHP if its a mobile agent: http://www.000webhost.com/forum/scripts-code-snippets/27404-php-extremely-simple-way-check-if-mobile-browser.html 使用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';
}
?>
Since you're using PHP I can recommend the php-mobile-detect class. 由于您使用的是PHP,因此我建议您使用php-mobile-detect类。 You can cater to individual devices/OS'es/browsers, or simply use
isMobile()
or isTablet()
as a catch-all. 您可以迎合各个设备/操作系统/浏览器的需求,或者简单地使用
isMobile()
或isTablet()
作为isTablet()
。
I usually do something like this: 我通常会这样:
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';
}
Then I just <?php echo $phone
;?> wherever I need it and it works a treat! 然后我只要在需要的地方
<?php echo $phone
;?>就可以了! And by using PHP instead of javascript it means the detection is done server-side, so the end user has less to download (like jQuery and extra scripts). 通过使用PHP而不是javascript,这意味着检测是在服务器端完成的,因此最终用户的下载量减少了(例如jQuery和其他脚本)。
The library of devices gets updated fairly often, so it's worth checking the GitHub page every so often. 设备库经常更新,因此值得经常检查GitHub页面 。
You want to detect, whether a user has a mobile browser or not? 您想检测用户是否具有移动浏览器? This might help:
这可能会有所帮助:
http://jquerybyexample.blogspot.com/2012/03/detect-mobile-browsers-using-jquery.html http://jquerybyexample.blogspot.com/2012/03/detect-mobile-browsers-using-jquery.html
Try this below one : 请尝试以下一种方法:
Syntex : callto 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.