js通过浏览器语言 设备跳转指定页面

//移动设备访问跳转

(function(){
var pathname = window.location.pathname;
pathnameobj = pathname.split(‘/’);
filename=pathnameobj[pathnameobj.length – 1];
// alert(filename);

var language=(navigator.browserLanguage || navigator.language).toLowerCase()
var ua=navigator.userAgent.toLowerCase();

var bIsIpad = ua.match(/ipad/i) == “ipad”;
var bIsIphoneOs = ua.match(/iphone os/i) == “iphone os”;
var bIsMidp = ua.match(/midp/i) == “midp”;
var bIsUc7 = ua.match(/rv:1.2.3.4/i) == “rv:1.2.3.4”;
var bIsUc = ua.match(/ucweb/i) == “ucweb”;
var bIsAndroid = ua.match(/android/i) == “android”;
var bIsCE = ua.match(/windows ce/i) == “windows ce”;
var bIsWM = ua.match(/windows mobile/i) == “windows mobile”;
//移动端
if(bIsIpad||bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM){
if(language.indexOf(‘zh’) > -1){
if(filename!=’m_index.html’)window.location.href = “m_index.html”;
}else{
if(filename!=’m_index_en.html’)window.location.href = “m_index_en.html”;
}
}
else//PC端
{
if(language.indexOf(‘zh’) > -1){
if(filename!=’index.html’)window.location.href = “index.html”;
}else{
if(filename!=’index_en.html’)window.location.href = “index_en.html”;
}
}

})();