root / snf-astakos-app / astakos / im / static / im / js / os.js @ b87429e1
History | View | Annotate | Download (2.8 kB)
1 |
//http://www.quirksmode.org/js/detect.html
|
---|---|
2 |
var BrowserDetect = {
|
3 |
init: function () { |
4 |
this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; |
5 |
this.version = this.searchVersion(navigator.userAgent) |
6 |
|| this.searchVersion(navigator.appVersion)
|
7 |
|| "an unknown version";
|
8 |
this.OS = this.searchString(this.dataOS) || "an unknown OS"; |
9 |
}, |
10 |
searchString: function (data) { |
11 |
for (var i=0;i<data.length;i++) { |
12 |
var dataString = data[i].string;
|
13 |
var dataProp = data[i].prop;
|
14 |
this.versionSearchString = data[i].versionSearch || data[i].identity;
|
15 |
if (dataString) {
|
16 |
if (dataString.indexOf(data[i].subString) != -1) |
17 |
return data[i].identity;
|
18 |
} |
19 |
else if (dataProp) |
20 |
return data[i].identity;
|
21 |
} |
22 |
}, |
23 |
searchVersion: function (dataString) { |
24 |
var index = dataString.indexOf(this.versionSearchString); |
25 |
if (index == -1) return; |
26 |
return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); |
27 |
}, |
28 |
dataBrowser: [
|
29 |
{ |
30 |
string: navigator.userAgent,
|
31 |
subString: "Chrome", |
32 |
identity: "Chrome" |
33 |
}, |
34 |
{ string: navigator.userAgent,
|
35 |
subString: "OmniWeb", |
36 |
versionSearch: "OmniWeb/", |
37 |
identity: "OmniWeb" |
38 |
}, |
39 |
{ |
40 |
string: navigator.vendor,
|
41 |
subString: "Apple", |
42 |
identity: "Safari", |
43 |
versionSearch: "Version" |
44 |
}, |
45 |
{ |
46 |
prop: window.opera,
|
47 |
identity: "Opera", |
48 |
versionSearch: "Version" |
49 |
}, |
50 |
{ |
51 |
string: navigator.vendor,
|
52 |
subString: "iCab", |
53 |
identity: "iCab" |
54 |
}, |
55 |
{ |
56 |
string: navigator.vendor,
|
57 |
subString: "KDE", |
58 |
identity: "Konqueror" |
59 |
}, |
60 |
{ |
61 |
string: navigator.userAgent,
|
62 |
subString: "Firefox", |
63 |
identity: "Firefox" |
64 |
}, |
65 |
{ |
66 |
string: navigator.vendor,
|
67 |
subString: "Camino", |
68 |
identity: "Camino" |
69 |
}, |
70 |
{ // for newer Netscapes (6+)
|
71 |
string: navigator.userAgent,
|
72 |
subString: "Netscape", |
73 |
identity: "Netscape" |
74 |
}, |
75 |
{ |
76 |
string: navigator.userAgent,
|
77 |
subString: "MSIE", |
78 |
identity: "Explorer", |
79 |
versionSearch: "MSIE" |
80 |
}, |
81 |
{ |
82 |
string: navigator.userAgent,
|
83 |
subString: "Gecko", |
84 |
identity: "Mozilla", |
85 |
versionSearch: "rv" |
86 |
}, |
87 |
{ // for older Netscapes (4-)
|
88 |
string: navigator.userAgent,
|
89 |
subString: "Mozilla", |
90 |
identity: "Netscape", |
91 |
versionSearch: "Mozilla" |
92 |
} |
93 |
], |
94 |
dataOS : [
|
95 |
{ |
96 |
string: navigator.platform,
|
97 |
subString: "Win", |
98 |
identity: "windows" |
99 |
}, |
100 |
|
101 |
{ |
102 |
string: navigator.userAgent.toLowerCase(),
|
103 |
subString: "android", |
104 |
identity: "Android" |
105 |
}, |
106 |
{ |
107 |
string: navigator.platform,
|
108 |
subString: "Mac", |
109 |
identity: "MacOS" |
110 |
}, |
111 |
{ |
112 |
string: navigator.userAgent,
|
113 |
subString: "iPhone", |
114 |
identity: "iPhone" |
115 |
}, |
116 |
{ |
117 |
string: navigator.userAgent,
|
118 |
subString: "iPad", |
119 |
identity: "iPad" |
120 |
}, |
121 |
{ |
122 |
string: navigator.platform,
|
123 |
subString: "Linux", |
124 |
identity: "linux" |
125 |
} |
126 |
] |
127 |
|
128 |
}; |
129 |
BrowserDetect.init(); |