JS检查IE版本

以下代码可检查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;
}
分享这个帖子:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

2个评论 to “JS检查IE版本”

  • simaopig 说:

    貌似我也有一个比较全的,明天发一下。呵呵。

    • CheonNii 说:

      其实我只要能检查到IE6就够用了,因为IE6一下已经放弃了,IE6也只是因为中国大部分用户还都是用IE6,只能去研究IE6的兼容性问题,其他浏览器都还好。
      IE6最烦的就是不能很好的支持半透明的PNG图片。

  • 留下评论:

    昵称(必须):
    邮箱地址 (不会被公开) (必须):
    站点
    评论 (必须)
    XHTML: 您可以使用这些标记: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>