Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Created September 11, 2012 21:47
Show Gist options
  • Save buzzedword/3702329 to your computer and use it in GitHub Desktop.
Save buzzedword/3702329 to your computer and use it in GitHub Desktop.
Minified UA library.
/*jslint browser: true, regexp: true, maxerr: 50, indent: 4 *//**
* A UserAgent detection library.
*
* This library relies on the navigator.userAgent property and hence does not
* work for custom UserAgent settings.
*
* Apart from supporting detection of major browser vendors, the library also
* supports detection of various devices.
*
* Copyright (c) 2012, Gopalarathnam Venkatesan
* All rights reserved.
*
* @module UA
*/var UA=function(){"use strict";var e=window.navigator&&navigator.userAgent||"";return{isChrome:function(){return/webkit\W.*(chrome|chromium)\W/i.test(e)},isFirefox:function(){return/mozilla.*\Wfirefox\W/i.test(e)},isGecko:function(){return/mozilla(?!.*webkit).*\Wgecko\W/i.test(e)},isIE:function(){return navigator.appName==="Microsoft Internet Explorer"},isKindle:function(){return/\W(kindle|silk)\W/i.test(e)},isMobile:function(){return/(iphone|ipod|(android.*?mobile)|blackberry|nokia)/i.test(e)},isOpera:function(){return/opera.*\Wpresto\W/i.test(e)},isSafari:function(){return/webkit\W(?!.*chrome).*safari\W/i.test(e)},isTablet:function(){return/(ipad|android(?!.*mobile))/i.test(e)},isTV:function(){return/googletv|sonydtv/i.test(e)},isWebKit:function(){return/webkit\W/i.test(e)},whoami:function(){return e}}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment