Javascript 常见的移动客户端userAgent特征识别

阅读(3672)

通过 navigator.userAgent 检测当前客户端的方式:


var ua = navigator.userAgent,

    android = ua.match(/(Android)\s+([\d.]+)/),
    ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
    ipod = ua.match(/(iPod).*OS\s([\d_]+)/),
    iphone = !ipod && !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
    kindle = ua.match(/Kindle\/([\d\.]+)/),    // Kindle

    weixin = ua.match(/MicroMessenger\/([^\s]+)/),     // 微信
    mqq = ua.match(/QQ\/([\d\.]+)/),                   // 手机QQ
    mqqbrowser = ua.match(/MQQBrowser\/([\d\.]+)/),    // QQ浏览器
    ucbrowser = ua.match(/UCBrowser\/([\d\.]+)/);      // UC浏览器

可识别 kindle、微信、手机QQ等。

Tags: useragent