【发布时间】:2013-06-20 23:53:21
【问题描述】:
我有一个网站 www.domain.com,我设计了一个新的移动版本 m.domain.com。但是如何检测移动设备并将其从 www.domain.com 重定向到 m.domain.com?
【问题讨论】:
-
链接到副本会很棒。我们是在谈论 2009 年的帖子吗?还是 2010 年?
标签: php javascript jquery css html
我有一个网站 www.domain.com,我设计了一个新的移动版本 m.domain.com。但是如何检测移动设备并将其从 www.domain.com 重定向到 m.domain.com?
【问题讨论】:
标签: php javascript jquery css html
我刚刚在谷歌搜索,这是第一个结果:
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())
【讨论】:
使用此代码检测移动设备,然后将其重定向:-
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
window.location = "m.domain.com";
}
</script>
test() 方法已用于测试字符串中的匹配项,如果找到匹配项,则会进行重定向。在页面顶部添加此代码。
【讨论】: