Detect IE6

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.

Posted in none. Tags: , . 4 Comments »

4 Responses to “Detect IE6”

  1. Dima Sabanin Says:

    Doesn’t work for me, it returns true for FF3.0.1 on Mac.

  2. Lea Verou Says:

    I use something similar:
    if(‘ActiveXObject’ in window && !(‘XMLHttpRequest’ in window)) // do stuff

    Nice blog, keep it up! :)


Leave a Reply