js判断移动设备

在开发中可能需要去判断用户的设备重定向到相应的网址:

  1. 判断 iPhone  Android  iPod  

if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/Android/i))||(navigator.userAgent.match(/iPod/i)))
        {
            window.location.href = 'http://playsteam.cn/';
        }
2.判断 iPad
if(navigator.userAgent.match(/iPad/i)) {
    window.location.href = 'http://playsteam.cn/';
}

 3. 判断安卓、苹果、winphone手机

function test(){
        var u = navigator.userAgent;
        if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
            console.log("安卓手机");
        } else if (u.indexOf('iPhone') > -1) {//苹果手机
            console.log("苹果手机");
        } else if (u.indexOf('Windows Phone') > -1) {//winphone手机
            console.log("winphone手机");
        }

    }


原文地址:https://www.cnblogs.com/zhangruiqi/p/8377215.html