.. _quickstart/browser-sniffing: Browser Sniffing ================ :Status: Draft :Version: 1.0 :Authors: Peter Higgins, Ben Lowery .. contents:: :depth: 2 You should try to use capability detection (http://dev.opera.com/articles/view/using-capability-detection/) when possible. When that is not an option, Dojo provides a number of ``is`` variables for browser detection, defined at runtime based on the users current browser. * dojo.isIE * dojo.isMozilla * dojo.isFF * dojo.isOpera * dojo.isSafari * dojo.isKhtml * dojo.isAIR - true if running within the Adobe AIR enviroment * dojo.isQuirks - is the browser in Quirks-Mode * dojo.isBrowser (not typically needed when only targeting browsers) For Dojo 1.3, the following were added: * dojo.isWebKit * dojo.isChrome Each variable is only defined if the specified browser is being used. For example, if you're using Internet Explorer, only dojo.isIE is defined; all the other variables are undefined. The variable holds the browser version number as a Number, so you can easily perform version checks. Additionally, since undefined always evaluates as false in if statements, you can use code like this to check for a certain browser version: .. code-block:: javascript :linenos: if(dojo.isIE <= 6){ // only IE6 and below ... } if(dojo.isFF < 3){ // only Firefox 2.x and lower ... } if(dojo.isIE == 7){ // only IE7 ... } ======== Examples ======== Here's a live sample to show how it works: .. codeviewer::
Is this Internet Explorer?
Is this Firefox?
Is this Mozilla?
Is this Opera?
Is this WebKit? (Dojo 1.3)
Is this Chrome? (Dojo 1.3)
Is this at least IE 7?
Is this at least Firefox 3?
Is this at least Opera 9?
======== See also ======== * :ref:`dojo._base.loader, the bootstrap module and home of the discussed variables `