通过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/post/5256.html
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。