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

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判断移动设备及操作系统

上一篇:Android ViewPager的每个页面的显示与销毁的时机


下一篇:grails-MappingException: Could not determine Type