javascript 如果安装了插件,如何检查 Firefox 和 Chrome

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4636407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 14:22:41  来源:igfitidea点击:

How do I check in Firefox and Chrome if a plugin is installed

javascriptfirefoxpluginsgoogle-chrome

提问by Jens Alm

I'm using an embedded plugin in my web app to enable scanning (Dynamsoft's webscanning plugin). I'm serving an xpi to firefox users and a crx to chrome users. When viewing the page without the plugin installed, Firefox will try to download the plugin and the user will need to click "manual install" to install it. Chrome will make no attempt to donwload the plugin (this is by design, according to http://code.google.com/p/chromium/issues/detail?id=15745)

我在我的网络应用程序中使用嵌入式插件来启用扫描(Dynamsoft 的网络扫描插件)。我正在为 Firefox 用户提供 xpi,为 chrome 用户提供 crx。在未安装插件的情况下查看页面时,Firefox 会尝试下载插件,用户需要点击“手动安装”进行安装。Chrome 不会尝试下载插件(这是设计使然,根据http://code.google.com/p/chromium/issues/detail?id=15745

I would like to use javascript to detect wether the plugin is installed or not (preferrably before trying to load it through the embed tag). If no plugin is installed, I want to provide an explanation and a link to the correct plugin to the user. Both browsers install their respective plugins without any problem if the user clicks at a download link instead of just trying to load through the embed tag.

我想使用 javascript 来检测插件是否安装(最好在尝试通过 embed 标签加载它之前)。如果没有安装插件,我想向用户提供一个解释和一个正确插件的链接。如果用户单击下载链接而不是仅尝试通过 embed 标签加载,则两个浏览器都会安装各自的插件而不会出现任何问题。

So, does anybody know a way detect wether a plugin is installed using javascript?

那么,有人知道一种检测插件是否使用 javascript 安装的方法吗?

回答by russau

Have you had a look at window.navigator.plugins?

你有没有看过window.navigator.plugins

..and the equivalent reference for webkit plugins-

..和 webkit插件的等效参考-

The Apple reference for the WebKit DOM appears to have disappeared. navigator.pluginsdoes work for me in Safari & Chrome. See a jsfiddle here: http://jsfiddle.net/2EaKD/

Apple 对 WebKit DOM 的引用似乎已经消失了。 navigator.plugins在 Safari 和 Chrome 中对我有用。在此处查看 jsfiddle:http: //jsfiddle.net/2EaKD/

回答by Uwe Keim

Sounds to me like a potential security hole, if a website (something remotely) could access your plug-ins (something locally). So I guess this is not possible.

如果网站(远程)可以访问您的插件(本地),这对我来说就像一个潜在的安全漏洞。所以我想这是不可能的。

回答by Felix Kling

Your addon can monitor which pages are opened by the user. If it is your page, you can make your addon set a global variable in that page and your page's JavaScript should be able to detect this.

您的插件可以监控用户打开了哪些页面。如果它是您的页面,您可以让您的插件在该页面中设置一个全局变量,您的页面的 JavaScript 应该能够检测到这一点。