Debian Codegraph @

demo/browser/ua.js

raw
1 /*
2 * ua.js
3 * $Revision: 1.2 $ $Date: 2003/02/07 16:04:17 $
4 */
5
6 /* ***** BEGIN LICENSE BLOCK *****
7 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8 *
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
13 *
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
17 * License.
18 *
19 * The Original Code is Netscape code.
20 *
21 * The Initial Developer of the Original Code is
22 * Netscape Corporation.
23 * Portions created by the Initial Developer are Copyright (C) 2001
24 * the Initial Developer. All Rights Reserved.
25 *
26 * Contributor(s): Bob Clary <[email protected]>
27 *
28 * ***** END LICENSE BLOCK ***** */
29
30 function xbDetectBrowser()
31 {
32 var oldOnError = window.onerror;
33 var element = null;
34
35 window.onerror = null;
36
37 // work around bug in xpcdom Mozilla 0.9.1
38 window.saveNavigator = window.navigator;
39
40 navigator.OS = '';
41 navigator.version = parseFloat(navigator.appVersion);
42 navigator.org = '';
43 navigator.family = '';
44
45 var platform;
46 if (typeof(window.navigator.platform) != 'undefined')
47 {
48 platform = window.navigator.platform.toLowerCase();
49 if (platform.indexOf('win') != -1)
50 navigator.OS = 'win';
51 else if (platform.indexOf('mac') != -1)
52 navigator.OS = 'mac';
53 else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
54 navigator.OS = 'nix';
55 }
56
57 var i = 0;
58 var ua = window.navigator.userAgent.toLowerCase();
59
60 if (ua.indexOf('opera') != -1)
61 {
62 i = ua.indexOf('opera');
63 navigator.family = 'opera';
64 navigator.org = 'opera';
65 navigator.version = parseFloat('0' + ua.substr(i+6), 10);
66 }
67 else if ((i = ua.indexOf('msie')) != -1)
68 {
69 navigator.org = 'microsoft';
70 navigator.version = parseFloat('0' + ua.substr(i+5), 10);
71
72 if (navigator.version < 4)
73 navigator.family = 'ie3';
74 else
75 navigator.family = 'ie4'
76 }
77 else if (ua.indexOf('gecko') != -1)
78 {
79 navigator.family = 'gecko';
80 var rvStart = ua.indexOf('rv:');
81 var rvEnd = ua.indexOf(')', rvStart);
82 var rv = ua.substring(rvStart+3, rvEnd);
83 var rvParts = rv.split('.');
84 var rvValue = 0;
85 var exp = 1;
86
87 for (var i = 0; i < rvParts.length; i++)
88 {
89 var val = parseInt(rvParts[i]);
90 rvValue += val / exp;
91 exp *= 100;
92 }
93 navigator.version = rvValue;
94
95 if (ua.indexOf('netscape') != -1)
96 navigator.org = 'netscape';
97 else if (ua.indexOf('compuserve') != -1)
98 navigator.org = 'compuserve';
99 else
100 navigator.org = 'mozilla';
101 }
102 else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
103 {
104 var is_major = parseFloat(navigator.appVersion);
105
106 if (is_major < 4)
107 navigator.version = is_major;
108 else
109 {
110 i = ua.lastIndexOf('/')
111 navigator.version = parseFloat('0' + ua.substr(i+1), 10);
112 }
113 navigator.org = 'netscape';
114 navigator.family = 'nn' + parseInt(navigator.appVersion);
115 }
116 else if ((i = ua.indexOf('aol')) != -1 )
117 {
118 // aol
119 navigator.family = 'aol';
120 navigator.org = 'aol';
121 navigator.version = parseFloat('0' + ua.substr(i+4), 10);
122 }
123 else if ((i = ua.indexOf('hotjava')) != -1 )
124 {
125 // hotjava
126 navigator.family = 'hotjava';
127 navigator.org = 'sun';
128 navigator.version = parseFloat(navigator.appVersion);
129 }
130
131 window.onerror = oldOnError;
132 }
133
134 xbDetectBrowser();
135