Skip to content

Instantly share code, notes, and snippets.

@pushandplay
Last active November 8, 2019 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pushandplay/9740636 to your computer and use it in GitHub Desktop.
Save pushandplay/9740636 to your computer and use it in GitHub Desktop.
Detect Browser version (Yandex.Browser support)
navigator.checkBrowser = ->
ua = navigator.userAgent
M = ua.match(/(opera|yabrowser|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)
if /trident/i.test(M[1])
tem = /\brv[ :]+(\d+)/g.exec(ua) or []
return name: 'ie', version: (tem[1] or '')
if M[1] is 'Chrome'
if (tem = ua.match(/\bOPR\/(\d+)/))?
return name: 'opera', version: tem[1]
if (tem = ua.match(/\bYaBrowser\/(\d+)/))?
return name: 'yabrowser', version: tem[1]
M = if M[2] then [M[1], M[2]] else [navigator.appName, navigator.appVersion, '-?']
if (tem = ua.match(/version\/(\d+)/i))?
M.splice(1, 1, tem[1])
name: M[0].toLowerCase()
version: M[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment