//plugin detection - doesn't work in IE
function hasPlugin(name){
name = name.toLowerCase();
for (var i=0; i < navigator.mimeTypes.length; i++){
if (navigator.mimeTypes[i].name.toLowerCase().indexOf(name) > -1){
return true;
}
}
return false;
}
//detect flash
alert(hasPlugin("Flash"));
在IE下不支持Netscape式的插件,在IE中检测插件的唯一方式 是使用专有的ActiveXObject类型,并创建一个特定插件的实例,IE是以COM对象的方式实现插件的,而COM对象使用唯一标识符来标识。所以,在IE下要检测特定插件,必须知道其COM标识符。比如Flash的标识符是ShockwaveFlash.ShockwaveFlash。
//plugin detection for IE
function hasIEPlugin(name){
try {
new ActiveXObject(name);
return true;
} catch (ex){
return false;
}
}
//detect flash
alert(hasIEPlugin("ShockwaveFlash.ShockwaveFlash"));
一般针对每个插件分别创建检测函数,而不是使用通用检测方法:(以检测Flash插件为例)
//detect flash for all browsers
function hasFlash(){
var result = hasPlugin("Flash");
if (!result){
result = hasIEPlugin("ShockwaveFlash.ShockwaveFlash");
}
return result;
}
//detect flash
alert(hasFlash());