-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbrowser.js
More file actions
68 lines (58 loc) · 1.6 KB
/
Copy pathbrowser.js
File metadata and controls
68 lines (58 loc) · 1.6 KB
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
// Copyright 2006 Google Inc.
// All Rights Reserved
//
// Author: Bret Taylor
// Class for parsing the browser user agent. We export a singleton, so
// typical usage looks like this:
//
// if (Browser.instance().isGeckoBased()) {
// ...
// }
//
function Browser() {
this.type_ = null;
this.version_ = 0;
if (!window.RegExp) return;
var AGENTS = [Browser.OPERA, Browser.IE, Browser.SAFARI, Browser.FIREFOX,
Browser.NETSCAPE, Browser.MOZILLA];
var agent = navigator.userAgent.toLowerCase();
for (var i = 0; i < AGENTS.length; i++) {
var agentStr = AGENTS[i];
if (agent.indexOf(agentStr) != -1) {
this.type_ = agentStr;
var versionExpr = new RegExp(agentStr + "[ \/]?([0-9]+(\.[0-9]+)?)");
if (versionExpr.exec(agent) != null) {
this.version_ = parseFloat(RegExp.$1);
}
break;
}
}
}
Browser.OPERA = "opera";
Browser.IE = "ie";
Browser.SAFARI = "safari";
Browser.FIREFOX = "firefox";
Browser.NETSCAPE = "netscape";
Browser.MOZILLA = "mozilla";
Browser.instance = function() {
if (!Browser.instance__) {
Browser.instance__ = new Browser();
}
return Browser.instance__;
}
Browser.prototype.type = function() {
return this.type_;
}
Browser.prototype.version = function() {
return this.version_;
}
Browser.prototype.isGeckoBased = function() {
return (this.type_ == Browser.FIREFOX || this.type_ == Browser.MOZILLA ||
this.type_ == Browser.NETSCAPE);
}
Browser.prototype.isIEBased = function() {
return this.type_ == Browser.IE;
}
Browser.prototype.isWebKitBased = function() {
return this.type_ == Browser.SAFARI;
}