電腦端模板footer.html里面寫上以下代碼:
<a href="javascript:dr_goto_pc();">電腦版</a> | <a href="javascript:dr_goto_mobile();">手機(jī)版</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('POSCMS_my_test_code')) { // 移動端鏈接地址 // 跳轉(zhuǎn)首頁 //document.location.href = 'http://m.POSCMS.net'; //跳轉(zhuǎn)對應(yīng)當(dāng)前頁的寫法 document.location.href = '{str_replace('www.POSCMS.net', 'm.POSCMS.net', $my_web_url)}'; } }); // 切換手機(jī)端 function dr_goto_mobile() { $.cookie('POSCMS_my_test_code', '1',{expires: 7, path: '/', domain: 'POSCMS.net'}); // 跳轉(zhuǎn)首頁 //document.location.href = 'http://m.POSCMS.net'; //跳轉(zhuǎn)對應(yīng)當(dāng)前頁的寫法 document.location.href = '{str_replace('www.POSCMS.net', 'm.POSCMS.net', $my_web_url)}'; } // 切換電腦端 function dr_goto_pc() { $.cookie('POSCMS_my_test_code', '1',{expires: 7, path: '/', domain: 'POSCMS.net'}); // 跳轉(zhuǎn)首頁 //document.location.href = 'http://www.POSCMS.net'; //跳轉(zhuǎn)對應(yīng)當(dāng)前頁的寫法 document.location.href = '{str_replace('m.POSCMS.net', 'www.POSCMS.net', $my_web_url)}'; } </script>
然后在手機(jī)端模板footer.html里面寫上以下代碼:
<a href="javascript:dr_goto_pc();">電腦版</a> | <a href="javascript:dr_goto_mobile();">手機(jī)版</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('POSCMS_my_test_code')) { // 電腦鏈接地址 // 跳轉(zhuǎn)首頁 //document.location.href = 'http://www.POSCMS.net'; //跳轉(zhuǎn)對應(yīng)當(dāng)前頁的寫法 document.location.href = '{str_replace('m.POSCMS.net', 'www.POSCMS.net', $my_web_url)}'; } }); // 切換手機(jī)端 function dr_goto_mobile() { $.cookie('POSCMS_my_test_code', '1', {expires: 7, path: '/', domain: 'POSCMS.net'}); // 跳轉(zhuǎn)首頁 //document.location.href = 'http://m.POSCMS.net'; //跳轉(zhuǎn)對應(yīng)當(dāng)前頁的寫法 document.location.href = '{str_replace('www.POSCMS.net', 'm.POSCMS.net', $my_web_url)}'; } // 切換電腦端 function dr_goto_pc() { $.cookie('POSCMS_my_test_code', '1',{expires: 7, path: '/', domain: 'POSCMS.net'}); // 跳轉(zhuǎn)首頁 //document.location.href = 'http://www.POSCMS.net'; //跳轉(zhuǎn)對應(yīng)當(dāng)前頁的寫法 document.location.href = '{str_replace('m.POSCMS.net', 'www.POSCMS.net', $my_web_url)}'; } </script>
這樣就可以在電腦端切換手機(jī)端了,統(tǒng)一跳轉(zhuǎn)到首頁!
www.POSCMS.net 是電腦域名,m.POSCMS.net是手機(jī)域名,domian:POSCMS.net,一定寫成這種格式,填寫根域名,否則切換回不成功的,到時候你把他們換成你自己的即可~~
文檔最后更新時間:2017-05-09 11:13:49