自适应两个页面pc端与移动端打开网页时跳转到对应的地址

实现像淘宝那样的,pc一个网址,切换移动另一个网址

pc:index.html
移动:m.html
设备判断(根据目前设备跳转对应url)

在js中写

function browserRedirect() {

var sUserAgent= navigator.userAgent.toLowerCase();

var bIsIpad= sUserAgent.match(/ipad/i) == "ipad";

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 (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {

window.location.href= 'm.html;

} else {

window.location= 'index.html';

}

}

browserRedirect();

 

posted @ 2021-01-07 10:03  凹凸曼啦  阅读(510)  评论(0编辑  收藏  举报