首页 > 移动平台 > 详细

最新最全的js判断移动设备及操作系统

时间:2014-04-17 18:46:08      阅读:287      评论:0      收藏:0      [点我收藏+]
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
var navigator = window.navigator,
    userAgent = navigator.userAgent,
    android = userAgent.match(/(Android)[\s\/]+([\d\.]+)/),
    ios = userAgent.match(/(iPad|iPhone|iPod)\s+OS\s([\d_\.]+)/),
    wp = userAgent.match(/(Windows\s+Phone)\s([\d\.]+)/),
    isWebkit = /WebKit\/[\d.]+/i.test(userAgent),
    isSafari = ios ? (navigator.standalone ? isWebkit : (/Safari/i.test(userAgent) && !/CriOS/i.test(userAgent) && !/MQQBrowser/i.test(userAgent))) : false,
    os = {};
 
if (android) {
    os.android = true;
    os.version = android[2];
}
if (ios) {
    os.ios = true;
    os.version = ios[2].replace(/_/g, ‘.‘);
    os.ios7 = /^7/.test(os.version);
    if (ios[1] === ‘iPad‘) {
        os.ipad = true;
    } else if (ios[1] === ‘iPhone‘) {
        os.iphone = true;
        os.iphone5 = window.screen.height == 568;
    } else if (ios[1] === ‘iPod‘) {
        os.ipod = true;
    }
}
if (wp) {
    os.wp = true;
    os.version = wp[2];
    os.wp8 = /^8/.test(os.version);
}

 

来源:maxzhang/ibox2 · GitHub  

最新最全的js判断移动设备及操作系统,布布扣,bubuko.com

最新最全的js判断移动设备及操作系统

原文:http://www.cnblogs.com/pannysp/p/3670244.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!