var ua = navigator.userAgent;
var brand = "";
var phone = [/IPHONE/gi, /huawei/gi, /mi/gi, /vivo/gi, /OPPO/gi, /samsung/gi, /SONY/gi, /Nokia/gi, /HTC/gi, /ZTE/gi, /Lenovo/gi, /ZUK/gi,]
if (phone[0].test(ua)) {
brand = "iPhone";
} else if (phone[1].test(ua)) {
brand = "HUAWEI";
} else if (phone[2].test(ua)) {
brand = "小米";
} else if (phone[3].test(ua)) {
brand = "vivo";
} else if (phone[4].test(ua)) {
brand = "OPPO";
} else if (phone[5].test(ua)) {
brand = "SAMSUNG";
} else if (phone[6].test(ua)) {
brand = "SONY";
} else if (phone[7].test(ua)) {
brand = "Nokia";
} else if (phone[8].test(ua)) {
brand = "HTC";
} else if (phone[9].test(ua)) {
brand = "ZTE";
} else if (phone[10].test(ua) || phone[11].test(ua)) {
brand = "Lenovo";
} else {
brand = "Android";
}
console.log(brand )
部分手机UA查询方式:http://www.fynas.com/ua/search?b=&d=%E5%8D%8E%E4%B8%BA
标签:brand,else,phone,主流,test,手机,ua,gi,设备 From: https://www.cnblogs.com/nyy-neal/p/17654814.html