zl程序教程

您现在的位置是:首页 >  前端

当前栏目

javascript学习笔记(十七)检测浏览器插件代码

2023-06-13 09:14:34 时间
复制代码代码如下:

//检测非IE浏览器插件函数
functionhasPlugin(name){
name=name.toLowerCase();
for(vari=0;i<navigator.plugins.length;i++){
if(navigator.plugins[i].name.toLowerCase().indexOf(name)>-1){
returntrue;
}
}
returnfalse;
}

//检测IE浏览器插件函数
functionhasIEPlugin(name){
try{
newActiveXObject(name);
returntrue;
}
catch(ex){
returnfalse;
}
}
//检测所有浏览器中的Flash
functionhasFlash(){
varresult=hasPlugin("Flash");
if(!result){
result=hasIEPlugin("ShockwaveFlash.ShockwaveFlash");
}
returnresult;
}
//检测所有浏览器中的QuickTime
functionhasQuickTime(){
varresult=hasPlugin("QuickTime");
if(!result){
result=hasIEPlugin("QuickTime.QuickTime");
}
returnresult;
}

alert(hasFlash());
alert(hasQuickTime());