blob: 6f4fe1c0b7fd3085dc54f18920e4c399ca5fa362 [file] [log] [blame]
Zhenkai Zhu5c2475b2013-02-26 22:57:31 -08001function detect() {
2
3 var nVer = navigator.appVersion;
4 var nAgt = navigator.userAgent;
5 var browserName = navigator.appName;
6 var fullVersion = '' + parseFloat(navigator.appVersion);
7 var majorVersion = parseInt(navigator.appVersion, 10);
8 var nameOffset, verOffset, ix;
9
10 // In Opera, the true version is after "Opera" or after "Version"
11 if ((verOffset = nAgt.indexOf("Opera")) != -1) {
12 browserName = "Opera";
13 fullVersion = nAgt.substring(verOffset + 6);
14 if ((verOffset = nAgt.indexOf("Version")) != -1) fullVersion = nAgt.substring(verOffset + 8);
15 }
16 // In MSIE, the true version is after "MSIE" in userAgent
17 else if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
18 browserName = "Microsoft Internet Explorer";
19 fullVersion = nAgt.substring(verOffset + 5);
20 }
21 // In Chrome, the true version is after "Chrome"
22 else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
23 browserName = "Chrome";
24 fullVersion = nAgt.substring(verOffset + 7);
25 }
26 // In Safari, the true version is after "Safari" or after "Version"
27 else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
28 browserName = "Safari";
29 fullVersion = nAgt.substring(verOffset + 7);
30 if ((verOffset = nAgt.indexOf("Version")) != -1) fullVersion = nAgt.substring(verOffset + 8);
31 }
32 // In Firefox, the true version is after "Firefox"
33 else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
34 browserName = "Firefox";
35 fullVersion = nAgt.substring(verOffset + 8);
36 }
37 // In most other browsers, "name/version" is at the end of userAgent
38 else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
39 browserName = nAgt.substring(nameOffset, verOffset);
40 fullVersion = nAgt.substring(verOffset + 1);
41 if (browserName.toLowerCase() == browserName.toUpperCase()) {
42 browserName = navigator.appName;
43 }
44 }
45 // trim the fullVersion string at semicolon/space if present
46 if ((ix = fullVersion.indexOf(";")) != -1) fullVersion = fullVersion.substring(0, ix);
47 if ((ix = fullVersion.indexOf(" ")) != -1) fullVersion = fullVersion.substring(0, ix);
48
49 majorVersion = parseInt('' + fullVersion, 10);
50 if (isNaN(majorVersion)) {
51 fullVersion = '' + parseFloat(navigator.appVersion);
52 majorVersion = parseInt(navigator.appVersion, 10);
53 }
54
55 //document.write(''
56 // +'Browser name = '+browserName+'<br>'
57 // +'Full version = '+fullVersion+'<br>'
58 // +'Major version = '+majorVersion+'<br>'
59 // +'navigator.appName = '+navigator.appName+'<br>'
60 // +'navigator.userAgent = '+navigator.userAgent+'<br>'
61 //)
62
63 if (browserName == "Safari" && fullVersion == "5.1.7") {
64 return false;
65 } else {
66 return true;
67 }
68}