Attack of the IE Conditional Comment
Just in time for Friday, James Padolsey wins the award for most creative Internet Explorer detection code:
JAVASCRIPT:
// ———————————————————-
// If you’re not in IE (or IE version is less than 5) then:
// ie === undefined
// If you’re in IE (>5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
// And to detect the version:
// ie === 6 // IE6
// ie> 7 // IE8, IE9 …
// ie <9 // Anything less than IE9
// ———————————————————-
var ie = (function(){
var undef, v = 3, div = document.createElement(‘div’);
// If you’re not in IE (or IE version is less than 5) then:
// ie === undefined
// If you’re in IE (>5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
// And to detect the version:
// ie === 6 // IE6
// ie> 7 // IE8, IE9 …
// ie <9 // Anything less than IE9
// ———————————————————-
var ie = (function(){
var undef, v = 3, div = document.createElement(‘div’);
while (
div.innerHTML = ‘<!–[if gt IE ‘+(++v)+’]><i></i><![endif]–>’,
div.getElementsByTagName(‘i’)[0]
);
return v> 4 ? v : undef;
}());
That’s a pretty creative use of IE Conditional Comments.
本文出自 传播、沟通、分享,转载时请注明出处及相应链接。
本文永久链接: https://www.nickdd.cn/?p=984
一条评论
@indian curry recipes
在后台发的,没多少心得,只是看到了就记下来即可.