在Javascript中判断ie版本

[复制链接]
查看11 | 回复2 | 2007-7-15 22:38:14 | 显示全部楼层 |阅读模式
利用javascript中的navigator对象中的userAgent属性可以判断用户的浏览器版本另外,navigator对象中还包含以下属性:appName:获取浏览器名称appVersion:获取浏览器的版本号信息appCodeName:获取浏览器代码名称userAgent:包含appName以及appVersion的所有信息platform:获取运行浏览器的平台信息language:获取浏览器支持的语言版本信息
回复

使用道具 举报

千问 | 2007-7-15 22:38:14 | 显示全部楼层
function Browser() { var ua, s, i; this.isIE
= false; // Internet Explorer this.isNS
= false; // Netscape this.version = null; ua = navigator.userAgent; s = "MSIE"; if ((i = ua.indexOf(s)) >= 0) {
this.isIE = true;
this.version = parseFloat(ua.substr(i + s.length));
return; } s = "Netscape6/"; if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = parseFloat(ua.substr(i + s.length));
return; } // Treat any other "Gecko" browser as NS 6.1. s = "Gecko"; if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = 6.1;
return; }}var browser = new Browser();转自:http://hi.baidu.com/lovemywolf/blog/item/622eb1446502f383b3b7dc48.html
回复

使用道具 举报

千问 | 2007-7-15 22:38:14 | 显示全部楼层
用 navigator.userAgent 参数, 判断其中是否包含"MSIE", 若有, 则说明是IE, 然后取得 MSIE 后及分号前的部分, 即IE的版本号.如, 可以用以下方式做测试:得到的是:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)然后写函数取获取版本号即可.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行