手机访问pc端自动跳转到手机版代码

虽然现在是html+css3的填下,自适应非常普及了,但是如果想做多套模板的话,还是可以采用手机端跳转的方式。

<script type="text/javascript">
function browserRedirect(url) {
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp"; 
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; 
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM){
  window.location.replace(url);              
}
}
browserRedirect("手机版地址");
</script>
最后修改:2018 年 09 月 06 日 12 : 30 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论