簡體   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