JS获取手机型号和系统
废话不多说,直接上源码
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> 7 <title>JS获取手机型号和系统</title> 8 </head> 9 10 <body> 11 <div id="app"></div> 12 </body> 13 <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> 14 <script src="mobile-detect.min.js"></script> <!-- mobile-detect可以通过npm下载 --> 15 <script> 16 //判断数组中是否包含某字符串 17 Array.prototype.contains = function(needle) { 18 for (i in this) { 19 if (this[i].indexOf(needle) > 0) 20 return i; 21 } 22 return -1; 23 } 24 25 var device_type = navigator.userAgent; //获取userAgent信息 26 console.log(device_type); //打印到页面 27 var md = new MobileDetect(device_type); //初始化mobile-detect 28 var os = md.os(); //获取系统 29 var model = ""; 30 if (os == "iOS") { //ios系统的处理 31 os = md.os() + md.version("iPhone"); 32 model = md.mobile(); 33 } else if (os == "AndroidOS") { //Android系统的处理 34 os = md.os() + md.version("Android"); 35 var sss = device_type.split(";"); 36 var i = sss.contains("Build/"); 37 if (i > -1) { 38 model = sss[i].substring(0, sss[i].indexOf("Build/")); 39 } 40 } 41 console.log(os + "---" + model); //打印系统版本和手机型号 42 $('#app').html(device_type + '</br></br>' + os + "---" + model); 43 </script> 44 45 </html>