I know how to test an ie version using the conditional comments. But, I found out a good and clean way to do it, by testing a javascript method and check if it's supported or not, like:
if( document.addEventListener ){
alert("you got IE9 or greater");
}
But, I don't know how to test it if it's an specific version (like, I want to do something if it's IE8, but not if it's IE7 or IE9 nor other version.
I could use James Panolsey's solution
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
}());
But it does test using Conditional Comments.
Why not Conditional Comments? Because of the Standards mode
. As Microsoft states in their website and in the dev center, they do NOT support it in their new versions:
Important As of Internet Explorer 10, conditional comments are no longer supported by standards mode. Use feature detection to provide effective fallback strategies for website features that aren't supported by the browser. For more info about standards mode, see Defining Document Compatibility.
Testing by a valid Method is more efficient in my POV, But I don't know how to do it in a way to specific the version ... ("Using this you can test for that version"). The only one that I know is the above one that I used as example. Is there others methods that I could use to test it? or not?