poscms手机网站切换

切换功能很简单,首先在后台关闭移动端的自动强制转向

blob.png

 

然后在电脑端模板footer.html里面写上以下代码:

<a href="javascript:dr_goto_pc();">电脑版</a> | <a href="javascript:dr_goto_mobile();">手机版</a>
<script type="text/javascript" src="{THEME_PATH}js/jquery.cookie.js"></script>
<script type="application/javascript">
    $(function(){
        var MobileUA = (function() {
            var ua = navigator.userAgent.toLowerCase();
            var mua = {
                IOS: /ipod|iphone|ipad/.test(ua), //iOS
                IPHONE: /iphone/.test(ua), //iPhone
                IPAD: /ipad/.test(ua), //iPad
                ANDROID: /android/.test(ua), //Android Device
                WINDOWS: /windows/.test(ua), //Windows Device
                TOUCH_DEVICE: ('ontouchstart' in window) || /touch/.test(ua), //Touch Device
                MOBILE: /mobile/.test(ua), //Mobile Device (iPad)
                ANDROID_TABLET: false, //Android Tablet
                WINDOWS_TABLET: false, //Windows Tablet
                TABLET: false, //Tablet (iPad, Android, Windows)
                SMART_PHONE: false //Smart Phone (iPhone, Android)
            };
            mua.ANDROID_TABLET = mua.ANDROID && !mua.MOBILE;
            mua.WINDOWS_TABLET = mua.WINDOWS && /tablet/.test(ua);
            mua.TABLET = mua.IPAD || mua.ANDROID_TABLET || mua.WINDOWS_TABLET;
            mua.SMART_PHONE = mua.MOBILE && !mua.TABLET;
            return mua;
        }());
        //SmartPhone
        if (MobileUA.SMART_PHONE && !$.cookie('finecms_my_test_code')) {
            // 移动端链接地址
            // 跳转首页
            document.location.href = 'http://m.finecms.net';
            //跳转对应当前页的写法
            //document.location.href = '{str_replace('www.finecms.net', 'm.finecms.net', dr_now_url())}';
        }
    });
    // 切换手机端
    function dr_goto_mobile() {
        $.cookie('finecms_my_test_code', '1',{expires: 7, path: '/', domain: 'finecms.net'});
        // 跳转首页
        document.location.href = 'http://m.finecms.net';
        //跳转对应当前页的写法
        //document.location.href = '{str_replace('www.finecms.net', 'm.finecms.net', dr_now_url())}';
    }
    // 切换电脑端
    function dr_goto_pc() {
        $.cookie('finecms_my_test_code', '1',{expires: 7, path: '/', domain: 'finecms.net'});
        // 跳转首页
        document.location.href = 'http://www.finecms.net';
        //跳转对应当前页的写法
        //document.location.href = '{str_replace('m.finecms.net', 'www.finecms.net', dr_now_url())}';
    }
</script>

 

然后在手机端模板footer.html里面写上以下代码:

<a href="javascript:dr_goto_pc();">电脑版</a> | <a href="javascript:dr_goto_mobile();">手机版</a>
<script type="text/javascript" src="{THEME_PATH}js/jquery.cookie.js"></script>
<script type="application/javascript">
    $(function(){
        var MobileUA = (function() {
            var ua = navigator.userAgent.toLowerCase();
            var mua = {
                IOS: /ipod|iphone|ipad/.test(ua), //iOS
                IPHONE: /iphone/.test(ua), //iPhone
                IPAD: /ipad/.test(ua), //iPad
                ANDROID: /android/.test(ua), //Android Device
                WINDOWS: /windows/.test(ua), //Windows Device
                TOUCH_DEVICE: ('ontouchstart' in window) || /touch/.test(ua), //Touch Device
                MOBILE: /mobile/.test(ua), //Mobile Device (iPad)
                ANDROID_TABLET: false, //Android Tablet
                WINDOWS_TABLET: false, //Windows Tablet
                TABLET: false, //Tablet (iPad, Android, Windows)
                SMART_PHONE: false //Smart Phone (iPhone, Android)
            };
            mua.ANDROID_TABLET = mua.ANDROID && !mua.MOBILE;
            mua.WINDOWS_TABLET = mua.WINDOWS && /tablet/.test(ua);
            mua.TABLET = mua.IPAD || mua.ANDROID_TABLET || mua.WINDOWS_TABLET;
            mua.SMART_PHONE = mua.MOBILE && !mua.TABLET;
            return mua;
        }());
        //SmartPhone
        if (!MobileUA.SMART_PHONE && !$.cookie('finecms_my_test_code')) {
            // 电脑链接地址
            // 跳转首页
            document.location.href = 'http://www.finecms.net';
            //跳转对应当前页的写法
            //document.location.href = '{str_replace('m.finecms.net', 'www.finecms.net', dr_now_url())}';
        }
    });
    // 切换手机端
    function dr_goto_mobile() {
        $.cookie('finecms_my_test_code', '1', {expires: 7, path: '/', domain: 'finecms.net'});
        // 跳转首页
        document.location.href = 'http://m.finecms.net';
        //跳转对应当前页的写法
        //document.location.href = '{str_replace('www.finecms.net', 'm.finecms.net', dr_now_url())}';
    }
    // 切换电脑端
    function dr_goto_pc() {
        $.cookie('finecms_my_test_code', '1',{expires: 7, path: '/', domain: 'finecms.net'});
        // 跳转首页
        document.location.href = 'http://www.finecms.net';
        //跳转对应当前页的写法
        //document.location.href = '{str_replace('m.finecms.net', 'www.finecms.net', dr_now_url())}';
    }
</script>

 

这样就可以在电脑端切换手机端了,统一跳转到首页!

 

 

 

www.finecms.net 是电脑域名,m.finecms.net是手机域名,domian:finecms.net,一定写成这种格式,填写根域名,否则切换回不成功的,到时候你把他们换成你自己的即可~~

 

 

 

原文地址: http://help.dayrui.com/index.php?c=show&id=2463

转载于:https://my.oschina.net/finecms/blog/842035

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值