【问题标题】:why does Mobiledetect.net script not detect iPhone?为什么 Mobiledetect.net 脚本无法检测到 iPhone?
【发布时间】:2015-07-29 05:06:00
【问题描述】:

我正在尝试使用此脚本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

【问题讨论】:

    标签: php android ios iphone mobile-devices


    【解决方案1】:

    您是在询问浏览器是否在移动设备上运行 (&&) 在平板电脑上运行:

    $detect-&gt;isMobile() &amp;&amp; $detect-&gt;isTablet()

    由于第二个条件,这仅适用于平板电脑,不适用于手机。如果您希望任何移动设备的条件为真,只需将其删除:

    &lt;?php if( $detect-&gt;isMobile() ){ ?&gt;

    【讨论】:

      猜你喜欢
      • 2016-12-04
      • 2012-01-16
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 2017-01-02
      • 2015-06-03
      • 1970-01-01
      相关资源
      最近更新 更多