首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用opencms重定向至移动网站

使用opencms重定向至移动网站
EN

Stack Overflow用户
提问于 2012-04-17 14:56:32
回答 2查看 348关注 0票数 1

我有一个使用OPENCMS开发的网站。现在我们已经开发了一个移动网站。如何将代码或模块添加到opencms,以便当用户从手机访问时,它将被重定向到手机网站。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-17 15:01:41

在编辑器中某一页的开头插入。

代码语言:javascript
复制
<?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');
    ?>
票数 1
EN

Stack Overflow用户

发布于 2012-04-20 09:49:39

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10186568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档