效果图
let system = {} let userAgent = navigator.userAgent // 获取微信版本 let systemInfo = userAgent.match(/MicroMessenger.*?(?= )/) if (systemInfo && systemInfo.length > 0) { system.wechat = systemInfo[0] } // 苹果手机 if (userAgent.includes('iPhone') || userAgent.includes('iPad')) { if (userAgent.includes('iPad')) { system.device = 'iPad' } else { system.device = 'iPhone' } // 获取操作系统版本 systemInfo = userAgent.match(/iPhone OS .*?(?= )/) if (systemInfo && systemInfo.length > 0) { system.system = systemInfo[0] } } // 安卓手机 if (userAgent.includes('Android')) { systemInfo = userAgent.match(/Android.*; ?(.*(?= Build))/) if (systemInfo && systemInfo.length > 1) { system.device = systemInfo[1] } // 获取操作系统版本 systemInfo = userAgent.match(/Android.*?(?=;)/) if (systemInfo && systemInfo.length > 0) { system.system = systemInfo[0] } } alert(JSON.stringify(system))
标签:&&,微信,system,includes,手机操作系统,版本,systemInfo,userAgent,match From: https://www.cnblogs.com/srqsl/p/17851636.html