Browser Sniffing

Status:Draft
Version:1.0
Authors:Peter Higgins, Ben Lowery

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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:

Table of Contents

Error in the documentation? Can’t find what you are looking for? Let us know!