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