在Javascript中判断ie版本

发布网友

我来回答

4个回答

热心网友

5.5版本以下的xmlhttp是以COM对象方式提供的,在脚本中调用COM方法不区分大小写。比如IE独有的Microsoft滤镜,可以使用apply()也可以使用Apply(),随便你。
但在6.0以是版本中的xmlhttprequest对象是native方式实现的,区分大小写,如以下语句
xmlHttp.setrequestheader("content-type","application/x-www-form-urlencoded");
在5.0中可以使用,7.0就不能识别setrequestheader,要写成setRequestHeader.

热心网友

利用javascript中的navigator对象中的userAgent属性可以判断用户的浏览器版本
另外,navigator对象中还包含以下属性:
appName:获取浏览器名称
appVersion:获取浏览器的版本号信息
appCodeName:获取浏览器代码名称
userAgent:包含appName以及appVersion的所有信息
platform:获取运行浏览器的平台信息
language:获取浏览器支持的语言版本信息

热心网友

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

热心网友

用 navigator.userAgent 参数, 判断其中是否包含"MSIE", 若有, 则说明是IE, 然后取得 MSIE 后及分号前的部分, 即IE的版本号.

如, 可以用以下方式做测试:

<script>
document.write(navigator.userAgent)
</script>

得到的是:
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)

然后写函数取获取版本号即可.

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com