【JS】检测插件

//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());




转载于:https://my.oschina.net/hin911/blog/371281

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值