是否可以通过JavaScript检测插件是否激活?
这样我通常会检测插件,例如 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]);
}
}
我不是在寻找十字架- 浏览器解决方案或想测试它是否正确。如何测试这个插件是否活跃?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
其他两个解决方案都可以查明插件是否已安装并已启用。
目前无法确定该插件是否已安装但已被禁用。
Navigator.plugins
不包含仍然安装的禁用插件。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.navigator.plugins
是一个数组,因此您可以在现代浏览器中使用foreach
并使用索引进行迭代,否则:您无法区分已禁用和不存在的插件。请记住,您可能需要重新启动浏览器才能使插件激活/停用生效。
navigator.plugins
is an array, so you'd usefor each
in modern browsers and iterate with an index otherwise: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.
如果相关插件被禁用,它不会出现在
navigator.plugins
中,也不会以其他方式暴露在页面上。If the plugin in question is disabled, it won't appear in
navigator.plugins
or be otherwise exposed to the page.