Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 1 | function 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; |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 9 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 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) |
| 15 | fullVersion = nAgt.substring(verOffset + 8); |
| 16 | } |
| 17 | // In MSIE, the true version is after "MSIE" in userAgent |
| 18 | else if ((verOffset = nAgt.indexOf("MSIE")) != -1) { |
| 19 | browserName = "Microsoft Internet Explorer"; |
| 20 | fullVersion = nAgt.substring(verOffset + 5); |
| 21 | } |
| 22 | // In Chrome, the true version is after "Chrome" |
| 23 | else if ((verOffset = nAgt.indexOf("Chrome")) != -1) { |
| 24 | browserName = "Chrome"; |
| 25 | fullVersion = nAgt.substring(verOffset + 7); |
| 26 | } |
| 27 | // In Safari, the true version is after "Safari" or after "Version" |
| 28 | else if ((verOffset = nAgt.indexOf("Safari")) != -1) { |
| 29 | browserName = "Safari"; |
| 30 | fullVersion = nAgt.substring(verOffset + 7); |
| 31 | if ((verOffset = nAgt.indexOf("Version")) != -1) |
| 32 | fullVersion = nAgt.substring(verOffset + 8); |
| 33 | } |
| 34 | // In Firefox, the true version is after "Firefox" |
| 35 | else if ((verOffset = nAgt.indexOf("Firefox")) != -1) { |
| 36 | browserName = "Firefox"; |
| 37 | fullVersion = nAgt.substring(verOffset + 8); |
| 38 | } |
| 39 | // In most other browsers, "name/version" is at the end of userAgent |
| 40 | else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < |
| 41 | (verOffset = nAgt.lastIndexOf('/'))) { |
| 42 | browserName = nAgt.substring(nameOffset, verOffset); |
| 43 | fullVersion = nAgt.substring(verOffset + 1); |
| 44 | if (browserName.toLowerCase() == browserName.toUpperCase()) { |
| 45 | browserName = navigator.appName; |
| 46 | } |
| 47 | } |
| 48 | // trim the fullVersion string at semicolon/space if present |
| 49 | if ((ix = fullVersion.indexOf(";")) != -1) |
| 50 | fullVersion = fullVersion.substring(0, ix); |
| 51 | if ((ix = fullVersion.indexOf(" ")) != -1) |
| 52 | fullVersion = fullVersion.substring(0, ix); |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 54 | majorVersion = parseInt('' + fullVersion, 10); |
| 55 | if (isNaN(majorVersion)) { |
| 56 | fullVersion = '' + parseFloat(navigator.appVersion); |
| 57 | majorVersion = parseInt(navigator.appVersion, 10); |
| 58 | } |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 60 | if (browserName == "Safari" && fullVersion == "5.1.7") { |
| 61 | return false; |
| 62 | } |
| 63 | else { |
| 64 | return true; |
| 65 | } |
Zhenkai Zhu | 5c2475b | 2013-02-26 22:57:31 -0800 | [diff] [blame] | 66 | } |