以下代码可检查IE版本,也可检查是否为IE
例子
if(ieVer('notie')) alert('Your browser is not IE!');
if(ieVer('isie')) alert('Your browser is IE!');
if(ieVer('not',8)) alert('Your browser is not IE8!');
if(ieVer('is',6)) alert('Your browser is IE6!');
if(ieVer('gt',5.5)) alert('Your IE browser version is greater than 5.5!');
if(ieVer('gte',6)) alert('Your IE browser version is greater than or equal to 6!');
if(ieVer('lte',7)) alert('Your IE browser version is less than or equal to 7!');
if(ieVer('it',8)) alert('Your IE browser version is less than 8!');
函数
/*
notie : Is not IE
isie : Is IE
is : Equal to ==
not : Not equal to !=
lte : Less than or equal to <=
lt : Less than <
gte : Greater than or equal to >=
gt : Greater than >
*/
function ieVer(c,i) {
var v = navigator.appVersion.replace(/(.*)MSIE /, '').replace(/\;(.*)/, '');
if(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4) {
if(c == 'isie') {
return true;
}
if(c == 'is') {
return (v == i);
}
if(c == 'not') {
return (v != i);
}
if(c == 'lte') {
return (v <= i);
}
if(c == 'lt') {
return (v < i);
}
if(c == 'gte') {
return (v >= i);
}
if(c == 'gt') {
return (v > i);
}
} else {
if(c == 'notie') {
return true;
}
}
return false;
}
貌似我也有一个比较全的,明天发一下。呵呵。
其实我只要能检查到IE6就够用了,因为IE6一下已经放弃了,IE6也只是因为中国大部分用户还都是用IE6,只能去研究IE6的兼容性问题,其他浏览器都还好。
IE6最烦的就是不能很好的支持半透明的PNG图片。