Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created August 22, 2014 06:52
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 hisasann/2c5cc96b100ff73603cc to your computer and use it in GitHub Desktop.
Save hisasann/2c5cc96b100ff73603cc to your computer and use it in GitHub Desktop.
var ua = navigator.userAgent.toLowerCase();
$.ua = {
isWindows: /windows/.test(ua), // Windows
isMac: /macintosh/.test(ua), // Mac
isIE: /msie (\d+)/.test(ua), // IE
isIE6: /msie (\d+)/.test(ua) && RegExp.$1 == 6, // IE6
isIE7: /msie (\d+)/.test(ua) && RegExp.$1 == 7, // IE7
isLtIE9: /msie (\d+)/.test(ua) && RegExp.$1 < 9, // IE9未満
isFirefox: /firefox/.test(ua), // Firefox
isWebKit: /applewebkit/.test(ua), // WebKit
isSafari: /safari/.test(ua) && !/chrome/.test(ua), // Safari
isChrome: /safari/.test(ua) && /chrome/.test(ua), // chrome
isTouchDevice: 'ontouchstart' in window, // touchDevice
isIOS: /i(phone|pod|pad)/.test(ua), // iOS
isIPhone: /i(phone|pod)/.test(ua), // iPhone, iPod touch
isIPad: /ipad/.test(ua), // iPad
isAndroid: /android/.test(ua), // Android
isAndroidMobile: /android(.+)?mobile/.test(ua) // Android mobile
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment