-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathua.js
executable file
·147 lines (132 loc) · 4.18 KB
/
ua.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* $Log: ua.js,v $
* Revision 1.9 2002/07/22 14:06:21 bc6ix
* fix license path, change version reporting to use 2 digits for each level
*
* Revision 1.8 2002/07/07 08:23:07 bc6ix
* fix line endings
*
* Revision 1.7 2002/05/14 16:52:52 bc6ix
* use CVS Log for revision history
*
*
*/
/* ***** BEGIN LICENSE BLOCK *****
* Licensed under Version: MPL 1.1/GPL 2.0/LGPL 2.1
* Full Terms at http://bclary.com/lib/js/license/mpl-tri-license.txt
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Netscape code.
*
* The Initial Developer of the Original Code is
* Netscape Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Bob Clary <[email protected]>
*
* ***** END LICENSE BLOCK ***** */
function xbDetectBrowser()
{
var oldOnError = window.onerror;
var element = null;
window.onerror = null;
// work around bug in xpcdom Mozilla 0.9.1
window.saveNavigator = window.navigator;
navigator.OS = '';
navigator.version = parseFloat(navigator.appVersion);
navigator.org = '';
navigator.family = '';
var platform;
if (typeof(window.navigator.platform) != 'undefined')
{
platform = window.navigator.platform.toLowerCase();
if (platform.indexOf('win') != -1)
navigator.OS = 'win';
else if (platform.indexOf('mac') != -1)
navigator.OS = 'mac';
else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
navigator.OS = 'nix';
}
var i = 0;
var ua = window.navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') != -1)
{
i = ua.indexOf('safari');
navigator.family = 'safari';
navigator.org = 'safari';
navigator.version = parseFloat('0' + ua.substr(i+7), 10);
}
else if (ua.indexOf('opera') != -1)
{
i = ua.indexOf('opera');
navigator.family = 'opera';
navigator.org = 'opera';
navigator.version = parseFloat('0' + ua.substr(i+6), 10);
}
else if ((i = ua.indexOf('msie')) != -1)
{
navigator.org = 'microsoft';
navigator.version = parseFloat('0' + ua.substr(i+5), 10);
if (navigator.version < 4)
navigator.family = 'ie3';
else
navigator.family = 'ie4'
}
else if (ua.indexOf('gecko') != -1)
{
navigator.family = 'gecko';
var rvStart = ua.indexOf('rv:');
var rvEnd = ua.indexOf(')', rvStart);
var rv = ua.substring(rvStart+3, rvEnd);
var rvParts = rv.split('.');
var rvValue = 0;
var exp = 1;
for (var i = 0; i < rvParts.length; i++)
{
var val = parseInt(rvParts[i]);
rvValue += val / exp;
exp *= 100;
}
navigator.version = rvValue;
if (ua.indexOf('netscape') != -1)
navigator.org = 'netscape';
else if (ua.indexOf('compuserve') != -1)
navigator.org = 'compuserve';
else
navigator.org = 'mozilla';
}
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))
{
var is_major = parseFloat(navigator.appVersion);
if (is_major < 4)
navigator.version = is_major;
else
{
i = ua.lastIndexOf('/')
navigator.version = parseFloat('0' + ua.substr(i+1), 10);
}
navigator.org = 'netscape';
navigator.family = 'nn' + parseInt(navigator.appVersion);
}
else if ((i = ua.indexOf('aol')) != -1 )
{
// aol
navigator.family = 'aol';
navigator.org = 'aol';
navigator.version = parseFloat('0' + ua.substr(i+4), 10);
}
else if ((i = ua.indexOf('hotjava')) != -1 )
{
// hotjava
navigator.family = 'hotjava';
navigator.org = 'sun';
navigator.version = parseFloat(navigator.appVersion);
}
window.onerror = oldOnError;
}
xbDetectBrowser();