Detectar versión de IE con Javascript
Detectar IE con Javascript
Con este pequeño script podemos detectar IE en javascript usando comentarios condicionales.
// If you’re not in <strong>IE</strong> (or <strong>IE</strong> version is less than 5) then:
// <strong>ie</strong> === undefined
// If you’re in <strong>IE</strong> (>5) then you can determine which version:
// <strong>ie</strong> === 7; // IE7
// Thus, to detect <strong>IE</strong>:
// if (<strong>ie</strong>) {}
// And to detect the version:
// <strong>ie</strong> === 6 // IE6
// <strong>ie</strong>> 7 // IE8, IE9 …
// <strong>ie</strong> <9 // Anything less than IE9
// ———————————————————-
var <strong>ie</strong> = (function(){
var undef, v = 3, div = document.createElement(‘div’);
while (
div.innerHTML = ‘<!–[if gt <strong>IE</strong> ‘+(++v)+’]><i></i><![endif]–>’,
div.getElementsByTagName(‘i’)[0]
);
return v> 4 ? v : undef;
}());</pre>
[/html]
Visto en Ajaxian