Skip to content

Instantly share code, notes, and snippets.

@fmontone
Last active September 14, 2020 13:11
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 fmontone/d2315da9794a43404166f50b82519760 to your computer and use it in GitHub Desktop.
Save fmontone/d2315da9794a43404166f50b82519760 to your computer and use it in GitHub Desktop.
Check if Javascript is running in browser and get User Agent
const inBrowser = typeof window !== 'undefined';
// CHECK USER AGENT
const UA = inBrowser && window.navigator.userAgent.toLowerCase();
const isIE = UA && /msie|trident/.test(UA);
const isIE9 = UA && UA.indexOf('msie 9.0') > 0;
const isEdge = UA && UA.indexOf('edge/') > 0;
const isAndroid = UA && UA.indexOf('android') > 0;
// "chrome" word appears in Chromium based as Edge and Chrome
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA) && !isEdge;
const isChrome = UA && /chrome\/\d+/.test(UA);
const isPhantom = UA && /phantomjs/.test(UA);
const isFF = UA && UA.match(/firefox\/(\d+)/);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment