Detect IE6 with jQuery or Conditional Comments
Posted August 18th, 2010 in Javascript
I rarely need to detect whether the user's browser is Internet Explorer version 6 but when working on some stylized drop down boxes using the Stylish Select Box jQuery plugin the customisation I had done wouldn't render in IE6 so I decided to make it so the plugin isn't used for that browser. This post shows a couple of different ways to detect if it's IE6 with jQuery and then regular Javascript using Internet Explorer's conditional comments.
Detect IE6 with jQuery's $.browser
jQuery supports a $.browser object which is deprecated and the jQuery developers suggest it should not be used, but there are no plans to remove it at the present time. It can easily be used to detect IE6 as shown in the following example:
var isIE6 = $.browser.msie && parseFloat($.browser.version) < 7;
I have covered the $.browser object previously here.
Detect IE6 using Conditional Comments
The second method is to use the conditional comment system which is built into Internet Explorer to set a variable as shown in the second example below:
<script type="text/javascript"> var isIE6 = false; </script> <!--[if lte IE 6]> <script type="text/javascript"> isIE6 = true; </script> <![endif]-->
The isIE6 variable is first initialized in a chunk of Javascript that is run by all browsers as false, and then change to true if the conditional comment is true. We need to initizlize the variable first so that subsequent calls to if(isIE6) { } do not result in a parse error in browsers other than IE6.
Related posts:
- Browser feature detection with jQuery $.support (Friday, February 5th 2010)
- Detecting the browser engine and version with jQuery (Tuesday, February 2nd 2010)
- jQuery Plug-ins (Tuesday, December 8th 2009)
- Targeting specific versions of Internet Explorer and other browsers with conditional comments (Wednesday, June 18th 2008)
- Using Internet Explorer Conditional Tags for Style Sheet Selection (Wednesday, May 21st 2008)

Comments
blog comments powered by Disqus