通过navigator.userAgent判断一些设备和环境类型,总结了一些:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
//系统 var webkit = ua.match(/Web[kK]it[/]{0,1}([\d.]+)/); var android = ua.match(/(Android);?[\s/]+([\d.]+)?/); var osx = !!ua.match(/\(Macintosh; Intel /); var ipad = ua.match(/(iPad).*OS\s([\d_]+)/); var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/); var webos = ua.match(/(webOS|hpwOS)[\s/]([\d.]+)/); var wp = ua.match(/Windows Phone ([\d.]+)/);var touchpad = webos && ua.match(/TouchPad/); //app var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/); var firefox = ua.match(/Firefox\/([\d.]+)/); var firefoxos = ua.match(/\((?:Mobile|Tablet); rv:([\d.]+)\).*Firefox\/[\d.]+/); var webview = !chrome && ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/); var safari = webview || ua.match(/Version\/([\d.]+)([^S](Safari)|[^M]*(Mobile)[^S]*(Safari))/); var qq = ua.match(/(QQBrowser)\/([\d.]+)/); var baidubox = ua.match(/baiduboxapp\/([\d.]+)/i); var baidubrowser = ua.match(/baidubrowser\/([\d.]+)/i); var weixin = ua.match(/MicroMessenger\/([\d.]+)/i); var iqiyi = ua.match(/iqiyi\s*IqiyiVersion\/([\d.]+)/i); var uc = ua.match(/(?:ucbrowser|ucweb)\/([\d.]+)/i) || typeof ucweb !== 'undefined'; var qqApp = ua.match(/(QQ)\/([\d.]+)/); var readApp = ua.match(/iqiyireader IqiyiReaderVersion\/([\d.]+)/i); // 爱奇艺阅读 var readPlugin = ua.match(/IqiyiVersion_Reader\/([\d.]+)/i); // 爱奇艺阅读插件 var youku = ua.match(/Youku\/([\d.]+)/i); var xigua = ua.match(/VideoArticle\/([\d.]+)/i); var toutiao = ua.match(/NewsArticle\/([\d.]+)/i); //设备 var oppo = ua.match(/OPPO (\w+) |OppoBrowser\/(\w+)/i); var vivo = ua.match(/vivo (\w+) /i); var sumsung = ua.match(/SM-(\w+) /i); var le = ua.match(/(?:Letv|Le) (\w+) Build/i); var mi = ua.match(/(?:MI) ([\w ]+) Build/i); var huawei = ua.match(/(?:HUAWEI ([\w-]+) Build)|(?:; (?:HW-)?([\w-]+) Build\/(?:HUAWEI|HONOR))/i); var redmi = ua.match(/(?:Redmi|HM) ([\w ]+) Build/i); var meizu = ua.match(/(((?:meizu\/|m|mx|PRO) ?(?:[0-9]+)) ?(?:\w*)) Build/i); |