当电脑端开启静态功能时,访问网站页面是不会进过php程序的,因此默认情况下程序是无法识别客户端的,那么我们只能通过js来识别客户端了
<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; if(ua.match(/MicroMessenger/i)=="micromessenger") { return true; } return mua; }()); //SmartPhone if (MobileUA.SMART_PHONE) { // 移动端链接地址 document.location.href = '{str_replace('www.POSCMS.net', 'm.POSCMS.net', $my_web_url)}'; } }); </script>
示例中www.POSCMS.net是电脑域名,m.POSCMS.net是手机域名,你改成你自己的即可
文档最后更新时间:2018-10-23 11:36:19