By : bit-labs Published On Wednesday, December 26, 2012, 02:02 In JavaScript
It’s lightweight (2kb gzipped or 3,8kb minified) JavaScript browser detector that can be used in all your web projects. It’s created to help you to write CSS or JavaScript code for any specific browser, version of browser or whatnot in a very easy way. Detect layout engine, OS, support for CSS features and more.
It is indispensable solution for building cross-browser and cross-platform web-sites and web-applications.
How it works? Very simple. It generates a list of classes with detailed information about browser, layout engine, OS, device and then attaches it to <html> tag.
Unlike well-known Modernizr, the CSS/JS Browser Determiner is mostly focused not on the browser features but on the browser and the device itself. But it also determines the support of common CSS features.
.opera .element {color:red} // All versions of Opera
.ie8 .element {color:red} // MSIE 8
.ie7_5 .element {color:red} // MSIE 7.5
.ie8- .element {color:red} // MSIE 8 or less
.chrome24- .element {color:red} // Chrome 24 or less (25 version is the maximum available)
.webkit .element {color:red} // Webkit based browsers such as Chrome, Safari, IOS, Android etc.
.gecko18 .element {color:red} // Browsers that based on Gecko v18
.macos .element {color:red} // Mac OS only
.windows .element {color:red} // Any version of Windows
.win7 .element {color:red} // Windows 7 only
.pc .element {color:red} // Any non-mobile computer including Mac OS
.mobile .element {color:red} // Any mobile device
.desktop .element {color:red} // Window width 980px or more
.iphone .element {color:red} // iPhone
.ipad.landscape .element {color:red} // iPad in landscape orientation
.android .element {color:red} // Device with Android OS
.android.crmo .element {color:red} // Chrome Mobile on Android OS
.mobile.tablet .element {color:red} // Only mobile device with current width of the window from 768px to 979px
.boxsizing .element {color:red} // Browser that supports the CSS3 box-sizing property
.no-gradient .element {color:red} // Browser that does not supports CSS3 gradients
.cookie .element {color:red} // Cookies enabled
.no-flash .element {color:red} // Flash is not installed
... and so much more! if (browser.ie && browser.version <= 8 ) {
// Code for MSIE 8 or less
}
if (browser.is_mobile) {
// Code for mobile devices
}
if (browser.is_old) {
// Code for old browsers such as:
// MSIE 9 or less
// Firefox 3.6 or less
// Safari 3.0 or less
// Opera 10.1 or less
}
if (browser.supports("border-radius")) {
// Code for browsers that supports the CSS3 border-radius property
}
if (browser.is_desktop) {
// Window width is 980px or more
} And much-much more.
chrome, safari, firefox, ie, konqueror, opera, operamobi, operamini, crmo, unknownfirefox18, firefox18-, firefox18_0 (but NOT firefox18_0- or firefox18_0_1234 or firefox18_0a1)webkit, gecko, trident, presto, khtmlgecko18, gecko18_0 (but NOT gecko18- or gecko18_0_1 or gecko18_0a1)iphone, ipod, ipad, blackberry, kindlewindows, win8, win7, vista, xp, win2003, cros, unix, linux, ios, android, unknown_osopacity, gradient, borderradius, borderimage, animation, transition, transform, textshadow, boxsizing, boxshadow. Or no-gradient, no-borderimage etc…pc, mobile (any non-mobile computer or mobile device)desktop, tablet, phone (according to window width)landscape, portrait (viewport orientation, according to window width and height)retina, touchscreen (or no-retina, no-touchscreen)cookie, flash, java (or no-cookie, no-flash, no-java)browser.is_modern — returns true if it’s a modern browser. Depends on whether browser supports the CSS3 transition propertybrowser.is_old — opposite of browser.is_modernbrowser.is_mobile — returns true if it’s a mobile devicebrowser.is_pc — any non-mobile computer, including Mac OSbrowser.is_desktop — window width 980px and morebrowser.is_tablet — window width 768px to 979pxbrowser.is_phone — window width is 767px or lessbrowser.is_retina — returns true if it’s Retina displaybrowser.is_touchscreen — — returns true if it’s touchscreen devicebrowser.name — the name of the browserbrowser.NAME — like browser.ie, browser.firefox etc. Returns true or undefinedbrowser.nameFull — returns the full name of the browser like “Firefox”, “Internet Explorer” etc.browser.version — the version of the browserbrowser.layout — the name of the layout engine, like “webkit”, “gecko”, “trident”, “presto”, “khtml” or “unknown”browser.LAYOUT_NAME — like browser.webkit, browser.gecko etc. Returns true or undefinedbrowser.layoutFull — full name of the layout engine, like “WebKit”, “Gecko”, “Trident”, “Presto”, “KHTML” or “Unknown”browser.layoutVersion — the version of the layout engine, like “533.1” for WebKit/533.1, “18.0” for Gecko/18.0, “18.0a1pre” for Gecko 18.0 Alpha 1 pre etc.browser.os — returns the short name of the operation system, like “windows”, “macos”, “cros”, “unix”, “linux”, “ios”, “android” or “unknown”browser.osFull — returns the full name of the operation system, like “Windows”, “Mac OS X”, “CrOS”, “Unix”, “Linux”, “iOS”, “Android” or “Unknown”browser.osVersion — returns the OS version string, like “7” for Windows 7, “4.2” for Android 4.2 etc.browser.device — returns the short name of the mobile device, like “iphone”, “ipad”, “ipod”, “blackberry” or “kindle”browser.deviceFull — returns the full name of the mobile device, like “iPhone”, “iPad”, “iPod”, “BlackBerry” or “Kindle”browser.supports.CSS_PROP — like browser.supports.opacity, browser.supports.gradient etc. Only predefined properties are alowed (“Common CSS properties” list). Please note that the second word must be capitalized like textShadow, borderRadius, boxSizing etc.browser.mode — returns “desktop”, “tablet” or “phone” according to the current width of the windowbrowser.orientation — browser window orientation like “landscape” or “portrait”browser.cookieEnabled — returns true if cookies are enabled in browserbrowser.flashEnabled — returns true if Flash Player is installed and enabled in browserbrowser.javaEnabled — returns true if JAVA is installed and enabled in browserbrowser.width() — returns the width of the browserbrowser.height() — returns the height of the browserbrowser.supports("css-prop") — determine whether browser supports the CSS property.Version 2.2 | 15 Dec 2013
- Fixed flash detection
- other bugfixes
Version 2.1 | 15 Oct 2013
- Fixed detection of Opera 15+, IE 11
- Switched back to “ie” property from “msie” in JavaScript API (so now it’s browser.ie)
Version 2.0.3 | 29 May 2013
- Live orientation (landscape, portrait) update for CSS
Version 2.0.2 | 24 May 2013
- Fixed detection of mobile devices
Version 2.0.1 | 11 May 2013
- Opera is moving to WebKit soon, so now we ready for that!
- Fixed a link to the documentation (moved to a new domain)
Version 2.0 | 23 Jan 2013
- Total reworking almoust from the ground up
- Even more powerful. Added support of new browsers, OS, layout engines, devices and other features
- New detection algorithm
- Now you can detect version of OS and layout engine with both CSS and JavaScript
- Updated demos
- New testing tool added (see Live preview)
- Replaced Firefox browser name from ”.mozilla” to ”.firefox”
- Replaced “ie” property to “msie” in JavaScript API (so now it’s browser.msie)
- Replaced Mac OS from ”.mac” to ”.macos”
- The same 4kb (minified)!
Version 1.0.5 | 01 Jan 2013
- Fixed window width detection
Version 1.0.4 | 28 Dec 2012
- Added OS: win8, win7, vista, xp
- Added Retina displays detection
Version 1.0.3 | 27 Dec 2012
- Added iOS detection support
- Fixed critical bug with Safari browsers
- Other changes and bug fixes