How to detect the Internet Explorer version in Javascript

It’s very easy:

var ieVer=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; }}()||@*/0;

/*@cc_on opens the conditional, while @*/ closes it. The code inside conditional comment is only read by Internet Explorer.

The code inside conditional comment establishes that every Internet Explorer version returns a number. The 0 number is outside of the conditional comment, so that other browsers will take 0 value.

If we want a desired function works only in Internet Explorer 6 and older we write a condition which requires an equal or lower to 6 value for the ieVer value:

if (ieVer<=6) {executedFunction();}

Know more