/msie 5\.[56789]/i
是一个REGEXP变量。
和
msie 5.5
msie 5.6
msie 5.7
msie 5.8
msie 5.9
对应。
这个是我写的函数。
是IE的就返回版本(字符串),否则就返回false
function GetIEVersion()
{
try
{
if(!window.clientInformation)return false;
if(window.clientInformation.appName.toLowerCase()!="microsoft internet explorer")return false;
if(window.clientInformation.appVersion.toLowerCase().indexOf("msie")==-1)return false;
var a=window.clientInformation.appVersion.toLowerCase().split(";");
for(var i=0;i<a.length;i++)
{
a[i]=a[i].replace(" ","");
if(a[i].indexOf("msie")==0)
{
var version=a[i].substr(4,a[i].indexOf(".")-2);
return version;
}
}
}
catch(exception)
{
}
return false;
}
是一个REGEXP变量。
和
msie 5.5
msie 5.6
msie 5.7
msie 5.8
msie 5.9
对应。
这个是我写的函数。
是IE的就返回版本(字符串),否则就返回false
function GetIEVersion()
{
try
{
if(!window.clientInformation)return false;
if(window.clientInformation.appName.toLowerCase()!="microsoft internet explorer")return false;
if(window.clientInformation.appVersion.toLowerCase().indexOf("msie")==-1)return false;
var a=window.clientInformation.appVersion.toLowerCase().split(";");
for(var i=0;i<a.length;i++)
{
a[i]=a[i].replace(" ","");
if(a[i].indexOf("msie")==0)
{
var version=a[i].substr(4,a[i].indexOf(".")-2);
return version;
}
}
}
catch(exception)
{
}
return false;
}
“Mozilla/4.0 (compatible; MSIE 5.0b; Windows 98)”
其中:MSIE 5.0b是关键字,就可以用上面方法判断浏览器是不是IE5.x版的了。老外的内容有些过时了,现在都有IE 6.0了,还嫌版本不够高吗。
如果要求IE5.0以上版本可以,可以自己编段代码试试。
上述的
/ /是把这个字符串括起来
msie 就是 ie 的特征字符串。
\.是"."
[56789]是56789的任一个数字,也就说5.5,5.6,5.7,也就是大于5.5,IE5.5以后的版本。
好边的.test我也不懂了
老外还是比较牛的,他判断ie55是为了patch其中的一个bug,
完整的代码如下:function hasSupport() { if (typeof hasSupport.support != "undefined")
return hasSupport.support;
var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
hasSupport.support = ( typeof document.implementation != "undefined" &&
document.implementation.hasFeature( "html", "1.0" ) || ie55 )
// IE55 has a serious DOM1 bug... Patch it!
if ( ie55 ) {
document._getElementsByTagName = document.getElementsByTagName;
document.getElementsByTagName = function ( sTagName ) {
if ( sTagName == "*" )
return document.all;
else
return document._getElementsByTagName( sTagName );
};
} return hasSupport.support;
}