通过UserAgent判断进行移动适配
nginx版
PC ==>> 移动
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)){rewrite ^/(.*)$ http://m.qiquanji.com/$1 permanent;}
移动 ==>> PC
if ($http_user_agent !~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)){rewrite ^/(.*)$ http://www.qiquanji.com.com/$1 permanent;}
js版
(function(){var ua=navigator.userAgent.toLowerCase();var bIsIpad=ua.match(/ipad/i)=="ipad";var bIsIphoneOs=ua.match(/iphone os/i)=="iphone os";var bIsAndroid=ua.match(/android/i)=="android";var bIsWM=ua.match(/windows mobile/i)=="windows mobile"; if(bIsIpad||bIsIphoneOs||bIsAndroid||bIsWM){}else{var url=window.location.href;url=url.replace("m","www");window.location.href=url}})();
本站声明:网站内容来源于网络,如有侵权,请联系我们https://www.qiquanji.com,我们将及时处理。
微信扫码关注
更新实时通知