Skip to content

Instantly share code, notes, and snippets.

@s-shin
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save s-shin/9171790 to your computer and use it in GitHub Desktop.

Select an option

Save s-shin/9171790 to your computer and use it in GitHub Desktop.
Detect user agent by CoffeeScript. Public domain :)
# ref: https://w3g.jp/blog/tools/js_browser_sniffing
UA =
ie: do ->
ie = false
ael = window.addEventListener?
ie = 6 if ael and not document.documentElement.style.maxHeight?
ie = 7 if not ie and ael and not document.querySelectorAll?
ie = 8 if not ie and ael and not document.getElementsByClassName?
ie = 9 if not ie and document.uniqueID and not window.matchMedia
ie = document.documentMode if not ie and document.uniqueID
ie
firefox: "MozAppearance" of document.documentElement.style
opera: window.opera?
chrome: window.chrome?
safari: not window.chrome? and \
"WebkitAppearance" of document.documentElement.style
mobile: window.orientation?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment