2009-05-27 23 views
8

¿Existe una forma rápida de obtener una lista en JavaScript de los complementos Active X disponibles?forma de Javascript para enumerar los complementos disponibles para IE

Necesito hacer una prueba para ver si un plugin se ha instalado antes de intentar ejecutarlo.

En efecto, quiero crear una página que diga 'Plugin instalado y funcionar correctamente' o haga que falle correctamente.

No estoy seguro de cómo fallar con elegancia si el complemento no está disponible.

Respuesta

10

Just try it.

try { 
    var plugin = new ActiveXObject('SomeActiveX'); 
} catch (e) { 
    alert("Error"); // Or some other error code 
} 
+0

Gracias. Preferiría poder ver si existe sin tener que crear instancias. Pero parece que es la única forma. –

+2

Correcto. En IE, no hay forma de verificar la existencia de un complemento sin intentar usarlo. – EricLaw

0

Tal vez este script puede ayudar

function detectPlugin() { 
// allow for multiple checks in a single pass 
var daPlugins = detectPlugin.arguments; 

// consider pluginFound to be false until proven true 
var pluginFound = false; 

// if plugins array is there and not fake 
if (navigator.plugins && navigator.plugins.length > 0) { 
var pluginsArrayLength = navigator.plugins.length; 

// for each plugin... 
for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++) { 

    // loop through all desired names and check each against the current plugin name 
    var numFound = 0; 
    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) { 

    // if desired plugin name is found in either plugin name or description 
    if((navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
     (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0)) { 
     // this name was found 
     numFound++; 
    } 
    } 
    // now that we have checked all the required names against this one plugin, 
    // if the number we found matches the total number provided then we were successful 
    if(numFound == daPlugins.length) { 
    pluginFound = true; 
    // if we've found the plugin, we can stop looking through at the rest of the plugins 
    break; 
    } 
} 
} 
return pluginFound;} // detectPlugin 

llamada usando esto para exemple

pluginFound = detectPlugin('Shockwave','Flash'); 
+0

¿Funciona esto en IE8? Estaba jugando con el objeto navegador anteriormente y la longitud de los complementos era cero. –

+0

Parece estar funcionando porque esta página http://www.unibanco.com.br/vste/_exc/_hom/index.asp usa la secuencia de comandos sin problemas. –

+3

Resulta que la matriz de complementos no está poblada en Internet Explorer. –

2

La etiqueta object mostrará lo que está dentro de él si el objeto no se pueden crear instancias:

<object ...> 
<p> 
So sorry, you need to install the object. Get it <a href="...">here</a>. 
</p> 
</object> 

Por lo tanto, la falla elegante está incorporada y no necesita usar ningún script.

0

Para Internet Explorer 11 se puede utilizar navigator.plugins JS API, pero hay que agregar claves registrey apropriate con el fin de IE11 para detectar que:

HKLM\SOFTWARE\Microsoft\Internet Explorer\NavigatorPluginsList 

o de 64 bits

HKLM\SOFTWARE\Wow6432\Microsoft\Internet Explorer\NavigatorPluginsList 

por ejemplo para el plugin con nombre "ABC" y el tipo MIME "application/abc":

  • añadir clave HKLM \ SOFTWARE \ Wow6432 \ Microsoft \ Internet Explorer \ NavigatorPluginsList \ ABC
  • crear subclave para cada MIME personalizado tipo compatible con el complemento, utilizando el valor de tipo MIME como el nombre de la subclave, por ejemplo "Application/abc"

A continuación, la comprobación de la existencia plug-in se realiza utilizando este código:

var plugin = navigator.plugins["<your plugin activex id>"]; 
if(plugin) { 
    //plugin detected 
} else { 
    //plugin not found 
} 

Más sobre esto aquí: http://msdn.microsoft.com/en-us/library/ie/dn423948(v=vs.85).aspx

Cuestiones relacionadas