Is it possible to detect if a plugin is activated or not through JavaScript?

一个人想着一个人 提交于 2019-12-04 04:33:08

问题


This way I would normally detect plugins, such as Flash Player:

for (var el in navigator.plugins) {
    if (navigator.plugins[el].name &&
        navigator.plugins[el].name.toLowerCase().indexOf('shockwave') !== -1) {
        console.log(navigator.plugins[el]);
    }
}

I'm not looking for a cross-browser solution or want to test if it is the right way or not. What is the way to test if this plugin is active or not?


回答1:


Both of the other solutions work to find out if a plugin is installed AND is enabled.

There is currently no way to find out if the plugin is installed but is disabled. Navigator.plugins does not contain disabled plugins which are still installed.




回答2:


navigator.plugins is an array, so you'd use for each in modern browsers and iterate with an index otherwise:

function pluginActive(pname) {
    for (var i = 0;i < navigator.plugins.length;i++) {
        if (navigator.plugins[i].name.indexOf(pname) != -1) {
            return true;
        }
    }
    return false;
}

console.log("Flash plugin " +
            (pluginsActive("Shockwave Flash") ? "active" : "not present"));

You can not distinguish plugins that are disabled and not present. Bear in mind that you may have to restart your browser before plugin activation / deactivation takes effect.




回答3:


If the plugin in question is disabled, it won't appear in navigator.plugins or be otherwise exposed to the page.



来源:https://stackoverflow.com/questions/6889412/is-it-possible-to-detect-if-a-plugin-is-activated-or-not-through-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!