我有一个使用 OPENCMS 开发的网站。现在我们开发了一个移动网站。我如何向 opencms 添加代码或模块,以便当用户从移动设备访问时,它将被重定向到移动网站。
问问题
349 次
2 回答
1
在编辑器中的一个页面的开头插入。
<?php
function detect_mobile()
{
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
$mobile = detect_mobile();
if($mobile === true)
header('Location: /mobile');
?>
于 2012-04-17T07:01:40.887 回答
1
<script type="text/javascript">
var url=***'http://yourmobilesite.com/***';
var host_name=document.location.hostname;
var request_uri=document.location.pathname;
var no_mobile=location.search;
var cookie=document.cookie;
function detect()
{
var ua=navigator.userAgent.toLowerCase();
var devices=['vnd.wap.xhtml+xml','sony','symbian','nokia','samsung','mobile',
'windows ce','epoc','opera mini','nitro','j2me','midp-','cldc-',
'netfront','mot','up.browser','up.link','audiovox','blackberry',
'ericsson','panasonic','philips','sanyo','sharp','sie-',
'portalmmm','blazer','avantgo','danger','palm','series60',
'palmsource','pocketpc','smartphone','rover','ipaq','au-mic',
'alcatel','ericy','vodafone','wap1','wap2','teleca',
'playstation','lge','lg-','iphone','android','htc','dream',
'webos','bolt','nintendo'];
for (var i in devices)
{
if (ua.indexOf(devices[i]) != -1)
{
return true
}
}
}
if (no_mobile!='?nomobile=1' && cookie.indexOf('no_mobile')==-1)
{
is_mobile=detect();
if (is_mobile)
{
window.location = url
}
}
else
{
if (cookie.indexOf('no_mobile') != -1)
{}
else
{
cookie_expires = new Date();
cookie_expires.setTime(cookie_expires.getTime()+60*60*24);
document.cookie = "no_mobile=1; expires="
+ cookie_expires.toGMTString()
+ "; path=/;"
}
}
</script>
于 2012-04-20T01:49:39.010 回答