Comments on: Detect IE in JS using conditional comments https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Clive Walkden https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1999 Fri, 17 Jun 2011 08:18:18 +0000 https://j11y.io/?p=1659#comment-1999 Like it a lot, nice and clean. Thanks for posting this. Nice to see new ways of detecting the bane of our lives!

]]>
By: OC Wedding Photographer https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1998 Wed, 30 Mar 2011 14:15:13 +0000 https://j11y.io/?p=1659#comment-1998 I like the code … It’s clean and short … Great work James

]]>
By: LEDs Lights https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1997 Thu, 10 Mar 2011 06:54:01 +0000 https://j11y.io/?p=1659#comment-1997 Hey James, That was useful clear, and helpful info as usual from Webapp. Thanks and keep on the good works. ..

]]>
By: James https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1996 Fri, 18 Feb 2011 02:42:10 +0000 https://j11y.io/?p=1659#comment-1996 @Nyuszika7H, @Aldo, you’re both missing the point. My solution doesn’t rely on feature detection/inference or sniffing the UA string. Both these things are considered bad-practice by some and so I wanted to offer a potential solution. There are smaller solutions available if you are not concerned about the arguments against.

]]>
By: Aldo_MX https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1995 Thu, 17 Feb 2011 19:52:55 +0000 https://j11y.io/?p=1659#comment-1995 @Nyuszika7H: I think you meant

var IE;
//@cc_on IE = parseFloat(navigator.appVersion);

So is not 40 bytes anymore 😛

Anyway, a more accurate IE detection:

<script>
var IE_Version;
var IE_Engine;
/*@cc_on
	@if( @_jscript_version < 9 )
	{
		if( @_jscript_version >= 5.8 )
			IE_Version = 8;
		else if( @_jscript_version >= 5.7 )
		{
			if( window.XMLHttpRequest )
				IE_Version = 7;
			else
				IE_Version = 6;
		}
		else if( @_jscript_version >= 5.6 )
			IE_Version = 6;
		else if( @_jscript_version >= 5.5 )
			IE_Version = 5.5;
		else if( @_jscript_version >= 5.1 )
			IE_Version = 5;
		else if( @_jscript_version >= 3 )
			IE_Version = 4;
		else
			IE_Version = 3;
	}
	@else
	{
		IE_Version = @_jscript_version;
	}
	@end
@*/
if(IE_Version)
{
	IE_Engine = parseFloat(navigator.appVersion);
}
</script>

This way you when IE_Version != IE_Engine the user is either using compatibility mode or cloaking

]]>
By: Nyuszika7H https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1994 Tue, 15 Feb 2011 12:08:10 +0000 https://j11y.io/?p=1659#comment-1994 James’ solution is 191 bytes minified, but mine is only 40.

]]>
By: Vince https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1993 Tue, 01 Feb 2011 02:30:36 +0000 https://j11y.io/?p=1659#comment-1993 Sure it’s cleaver, but how is this any different from testing navigator.appName and all the other navigator.* properties ?

You’ve still got to put IE specific code in regardless.

]]>
By: Nyuszika7H https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1992 Sun, 30 Jan 2011 16:30:35 +0000 https://j11y.io/?p=1659#comment-1992 There’s a much easier way to do that.

var IE;
//@cc_on IE = navigator.appVersion;

Usage: if (IE) {...}, if (IE <= 6) {...}, if (IE < 9) {...}, if (IE == 7) {...} etc.

//@cc_on is a conditional comment, just like <!--[if IE]>. Since it’s a comment, other browsers will just ingore it.

]]>
By: erd https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1991 Fri, 21 Jan 2011 21:03:41 +0000 https://j11y.io/?p=1659#comment-1991 Thanks its always good to be able to see who is still using the very bad ie browser.

]]>
By: prochor666 https://j11y.io/snippets/detect-ie-in-js-using-conditional-comments/#comment-1990 Wed, 08 Dec 2010 18:36:21 +0000 https://j11y.io/?p=1659#comment-1990 W000000000W :). Realy nice.

]]>