Since people keep looking for this, here is how you can identify IE 6 (and IE 6 only):
<script type="text/javascript"> //<![CDATA[ var is_ie6 = ( window.external && typeof window.XMLHttpRequest == "undefined" ); //]]> </script>
This is reliable and even Opera is not pretending to be IE6 with this check. This is mostly useful to determine whether the PNG/Alpha Image Loader hack needs to be applied.
UPDATE:
The code provided by Lea Verou below performs up to 50% faster on all browsers except Firefox 2 and Google Chrome (where this test is really slow for some reason; maybe the in operator has not been optimized?)
<script type="text/javascript"> //<![CDATA[ var is_ie6 = ('ActiveXObject' in window && !('XMLHttpRequest' in window)); //]]> </script>
I cannot wait for the day when we do not have to deal with IE6 anymore. Considering how many intranet applications exist that specifically target this browser, this day may be in a distant future, unfortunately.
September 15, 2008 at 3:06 am
Doesn’t work for me, it returns true for FF3.0.1 on Mac.
May 11, 2009 at 11:00 am
@Dima: I just tested with FF 2.0.20 and FF 3.0.10. It works as expected in both (returning false).
February 19, 2009 at 2:05 am
I use something similar:
if(‘ActiveXObject’ in window && !(‘XMLHttpRequest’ in window)) // do stuff
Nice blog, keep it up!
April 2, 2009 at 7:35 pm
[...] Detect IE6 [...]