使用opencms重定向到移动网站

问题描述:

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

+0

这不回答这个问题,但可能会有所帮助: http://www.opencms-wiki.org/wiki/Creating_Mobile_Templates_with_OpenCms_8 – 2012-12-14 05:09:33

插入编辑器中某个页面的开头。

<?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

道歉:OpenCms的是基于Java的... – Scott 2012-04-17 07:03:14

+0

烨它基于Java 。所以我想知道在OpenCMS中是否有任何模块。 – Hacker 2012-04-17 07:08:59

+1

这里没有模块,因为它实际上几乎只是一个单线程,就像Scott上面抽样一样。只需将逻辑转换为Java并将其放置在OpenCms中的主要jsp模板中即可。这应该是全部。要么(做一个头重定向),或者如果它适合你,只需包含不同的CSS。我想这实际上取决于每种情况。 – 2012-04-17 23:50:17

<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>