繁体   English   中英

Javascript方式列出IE的可用插件

[英]Javascript way to list available plugins for IE

有没有一种快速的方法来获取可用的Active X插件的JavaScript列表?

我需要做一个测试,看看在我真正尝试运行它之前是否安装了插件。

实际上,我想创建一个页面,上面写着“已安装插件并正常工作”,或者让它优雅地失败。

如果插件不可用,我不确定如何优雅地失败。

try吧。

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

如果对象无法实例化, object标签将显示其中的内容:

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

因此,内置优雅故障,您根本不需要使用脚本。

对于Internet Explorer 11,您可以使用navigator.plugins JS API,但是您需要添加适当的registrey密钥以便IE11检测它:

HKLM\SOFTWARE\Microsoft\Internet Explorer\NavigatorPluginsList

或64位

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

例如,对于名称为“ABC”且mime类型为“application / abc”的插件:

  • 添加密钥HKLM \\ SOFTWARE \\ Wow6432 \\ Microsoft \\ Internet Explorer \\ NavigatorPluginsList \\ ABC
  • 为插件支持的每种自定义MIME类型创建子项,使用MIME类型值作为子项的名称,例如“application / abc”

然后使用以下代码检查插件是否存在:

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

更多相关信息: http//msdn.microsoft.com/en-us/library/ie/dn423948(v = vs。85).aspx

也许这个脚本可以帮助

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

以此为例来调用它

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM