我有一个网站 www.domain.com,并且我设计了一个新的移动版本 m.domain.com。但是如何检测移动设备并将它们从 www.domain.com 重定向到 m.domain.com?
问问题
21902 次
2 回答
3
我刚刚在谷歌搜索,这是第一个结果:
include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
// Check for any mobile device.
if ($detect->isMobile())
// Check for any tablet.
if($detect->isTablet())
// 3. Check for any mobile device, excluding tablets.
if ($detect->isMobile() && !$detect->isTablet())
于 2013-06-24T13:00:48.717 回答
1
使用此代码检测移动设备,然后将其重定向:-
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
window.location = "m.domain.com";
}
</script>
该test()
方法已用于测试字符串中的匹配项,如果找到匹配项,则进行重定向。在页面顶部添加此代码。
于 2013-06-24T13:00:59.153 回答