微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 检测移动设备或平板电脑设备

我的目标是建立一个移动网站(用于手机和平板电脑)和一个基于wordpress的响应式桌面网站.我想要最简单的方法来实现万无一失的设备检测.

移动网站将拥有许多功能,这些功能只会使触控设备受益,并将为手机和平板电脑定制设计.桌面网站将完全不同(具有相同的页面,但具有额外的内容),并且将完全响应,以防任何设备滑过检测.

我有一个将检测触摸设备并重定向到另一个页面的衬垫,但它似乎太简单,不能成为设备检测的万无一失的方法.这有多傻瓜?它适用于WindowsAndroid设备以及iOS吗?

这是我第一次做这样的网站,并不确定这将是多么有效:

<!-- Redirect to the mobile index page if we're on a touch device -->
<script>if( 'ontouchstart' in window ) window.location = 'mobile.html';</script>

解决方法

您可以使用 mdetect(移动检测)库为您执行此操作.它以多种语言编写,可以检测Windows,Android,iOS等.请务必阅读文档.

> PHP Version
> JavaScript Version

请注意,JavaScript版本包含此警告:

// WARNING: 
//   These JavaScript-based device detection features may ONLY work 
//   for the newest generation of smartphones,such as the iPhone,//   Android and Palm WebOS devices.
//   These device detection features may NOT work for older smartphones 
//   which had poor support for JavaScript,including 
//   older BlackBerry,PalmOS,and Windows Mobile devices. 
//   Additionally,because JavaScript support is extremely poor among 
//   'feature phones',these features may not work at all on such devices.
//   For better results,consider using a server-based version of this code,//   such as Java,APS.NET,PHP,or Ruby.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐