Skip to content

Instantly share code, notes, and snippets.

@botmaster
Forked from bitfishxyz/browser.js
Created April 4, 2020 11:55
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 botmaster/dfe41b8308d025b7e9fc447af7b86a25 to your computer and use it in GitHub Desktop.
Save botmaster/dfe41b8308d025b7e9fc447af7b86a25 to your computer and use it in GitHub Desktop.
const inBrowser = typeof window !== 'undefined'
// get user agent
const UA = inBrowser && window.navigator.userAgent.toLowerCase()
// detect browser
const isIE = UA && /msie|trident/.test(UA)
const isIE9 = UA && UA.indexOf('msie 9.0') > 0
const isEdge = UA && UA.indexOf('edge/') > 0
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
const isPhantomJS = UA && /phantomjs/.test(UA)
const isFF = UA && UA.match(/firefox\/(\d+)/)
// detect OS
const isAndroid = UA && UA.indexOf('android') > 0
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment