Skip to content

Instantly share code, notes, and snippets.

@jakub-g
Created December 21, 2020 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakub-g/b55cb5a30d1dea24b5ff1226a23c2a29 to your computer and use it in GitHub Desktop.
Save jakub-g/b55cb5a30d1dea24b5ff1226a23c2a29 to your computer and use it in GitHub Desktop.
legacy-browser-detection-ua-sniffing.js
(function() {
var isIE = typeof document.documentMode !== 'undefined'
var chromeVersion = navigator.userAgent.match(/Chrome\/(\d+)/) || undefined
chromeVersion = chromeVersion && parseInt(chromeVersion[1])
var firefoxVersion = navigator.userAgent.match(/Firefox\/(\d+)/) || undefined
firefoxVersion = firefoxVersion && parseInt(firefoxVersion[1])
var edgeVersion = navigator.userAgent.match(/Edge\/(\d+)/) || undefined
edgeVersion = edgeVersion && parseInt(edgeVersion[1])
var safariVersion = (!chromeVersion && !navigator.userAgent.match(/Tizen/)
&& navigator.userAgent.match(/Version\/(\d+).*Safari\//))
|| undefined
safariVersion = safariVersion && parseInt(safariVersion[1])
// Checking precisely for Safari version = 9 because there are too many false positives
// from niche browsers having Version/4 or Version/5 in URL (old Androids, Samsung TV WebViews...)
var isLegacy = isIE || chromeVersion < 47 || firefoxVersion < 48 || edgeVersion < 17 || safariVersion === 9
if (isLegacy) {
// ...
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment