Contenido

Detectar plugins instalados en Internet Explorer

15 May

+ 5

Si estás usando window.ActiveXObject() para aportar alguna funcionalidad extra a tus aplicaciones deberías revisar que dicha funcionalidad está disponible, ya sea por que se trata de un navegador diferente o por que el usuario no lo tenga instalado.

Para ello podemos usar el objeto plugins, basado en la recopilación de 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;}
	}
}

Modo de empleo

if (plugins.hasFlash()) {
   .... tiene flash ...
} else {
   .... no tiene flash ...
}

Demo

He montado una mini demo para verlo funcionar. Podeis verla aqui.

Comentar

#

Me reservo el derecho de eliminar y/o modificar los comentarios que contengan lenguaje inapropiado, spam u otras conductas no apropiadas en una comunidad civilizada. Si tu comentario no aparece, puede ser que akismet lo haya capturado, cada día lo reviso y lo coloco en su lugar. Siento las molestias.