Aprenda a detectar plugins instalados no Internet Explorer
Postado em: 19 de maio de 2008 por Pedro RogérioCaso você precise adicionar funcionalidades em suas aplicações, é necessário verificar antes se o usuário possui o complemento instalado em seu micro, pois caso contrário você pode alertá-lo disso e não ter problemas com suas aplicações. Isso pode ocorrer quando você está fazendo o uso do window.ActiveXObject(). Abaixo você vê uma recompilação dos detectores de plugins para Internet Explorer:
var plugins = {
hasAcrobat:function() {
if (!window.ActiveXObject) return false;
try { if (new ActiveXObject('AcroPDF.PDF')) return true;}
catch (e) {}
try { if (new ActiveXObject('PDF.PdfCtrl')) return true;}
catch (e) {}
return false;
},
hasFlash: function() {
if (!window.ActiveXObject) return false;
try {if (new ActiveXObject('ShockwaveFlash.ShockwaveFlash')) return true;}
catch (e) { return false;}
},
hasJava: function() {
return (!navigator.javaEnabled());
},
hasQuickTime: function() {
if (!window.ActiveXObject) return false;
try { if (new ActiveXObject('QuickTime.QuickTime')) return true;}
catch (e) {}
try {if(new ActiveXObject('QuickTimeCheckObject.QuickTimeCheck')) return true;}
catch (e) {};
return false;
},
hasRealPlayer: function() {
if (!window.ActiveXObject) return false;
var definedControls = [
'rmocx.RealPlayer G2 Control',
'rmocx.RealPlayer G2 Control.1',
'RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)',
'RealVideo.RealVideo(tm) ActiveX Control (32-bit)',
'RealPlayer'
];
for (var i = 0; i < definedControls.length; i++) {
try {if(new ActiveXObject(definedControls[i])) return true;}
catch (e) {continue;}
}
return false;
},
hasShockwave: function() {
if (!window.ActiveXObject) return false;
try {if(new ActiveXObject(’SWCtl.SWCtl’)) return true;}
catch (e) {return false;}
},
hasWMP: function() {
if (!window.ActiveXObject) return false;
try {if(new ActiveXObject(’WMPlayer.OCX’)) return true;}
catch (e) { return false;}
}
}
Exemplo
if (plugins.hasFlash()) {
.... você possui o plugin do flash ...
} else {
.... você não possui o plugin do flash ...
}
Demo
Você pode ver uma demonstração de uso aqui.








Micox disse: 27.05.08 ás 15:15
Muito, muito bom cara.