我正在尝试使用此脚本检测设备 http://mobiledetect.net/
但它没有检测到 iPhone。
header.php:
<?php
require_once 'include/Mobile_Detect.php';
$detect = new Mobile_Detect; ?>
device.php:
<?php include 'include/header.php'; ?>
<?php if( $detect->isMobile() && $detect->isTablet() ){ ?>
<script type='text/javascript'>
alert("I am mobile");
</script>
<?php } else { ?>
<script type='text/javascript'>
alert("I am desktop");
</script>
<? } ?>
当我检查桌面上的页面时,我会弹出以下消息:
I am desktop
- 正如我所料当我在 android 平板电脑上查看页面时,我会弹出以下消息:
I am mobile
- 正如我所料当我在 iPhone 上查看页面时,我会弹出以下消息:
I am desktop
- 不像预期的那样。为什么是这样?
这里是 PAGE
最佳答案
您在询问浏览器是否在移动设备上运行 和 (&&) 在平板电脑上:$detect->isMobile() && $detect->isTablet()
由于第二个条件,这仅适用于平板电脑,不适用于手机。如果您希望任何移动设备的条件为真,只需将其删除:<?php if( $detect->isMobile() ){ ?>
关于php - 为什么 Mobiledetect.net 脚本无法检测到 iPhone?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31691589/