Javascript 在不同浏览器下检测已安装的插件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5188908/
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
Detecting installed plugins under different browsers?
提问by tftd
I'm wondering if there is a way to detect installed plugins on different browsers. So far I have found that you can "detect" plugins on firefox by trying to guess if chrome://path/to/some/plugin/image.gif exists.
我想知道是否有办法检测不同浏览器上已安装的插件。到目前为止,我发现您可以通过尝试猜测 chrome://path/to/some/plugin/image.gif 是否存在来“检测”firefox 上的插件。
This code for firefox looks like this:
Firefox 的此代码如下所示:
<img src="chrome://firebug/content/blank.gif" onload="var a=document.getElementById('FireBug'); a.innerHTML = 'You are using FireBug';" style="visibility:hidden">
<div id="FireBug">You are not using FireBug</div>
I'm interested how does the code look in IE (more important to me) and if there are other ways to accomplish this task for other browsers too?
我感兴趣的是代码在 IE 中的外观(对我来说更重要),以及是否还有其他方法可以为其他浏览器完成此任务?
I want to know because I'm having an idiot client who claims he doesn't have installed plugins though I'm 99,99% sure he has. The problem is that some of those plugins are breaking parts of a web site admin control panel I've wrote.
我想知道,因为我有一个白痴客户声称他没有安装插件,尽管我 99,99% 确定他安装了。问题是其中一些插件破坏了我编写的网站管理控制面板的一部分。
Anyway I'd be glad to hear any tips,tricks,workarounds and etc for getting the plugin list of the popular browsers (ff,ie,opera,chrome,safari) :)
无论如何,我很高兴听到有关获取流行浏览器(ff、ie、opera、chrome、safari)插件列表的任何提示、技巧、解决方法等:)
回答by Hackaholic
This code will list all the plugins installed in the browser
此代码将列出浏览器中安装的所有插件
<html>
<body>
<div id="example"></div>
<script type="text/javascript">
var x=navigator.plugins.length; // store the total no of plugin stored
var txt="Total plugin installed: "+x+"<br/>";
txt+="Available plugins are->"+"<br/>";
for(var i=0;i<x;i++)
{
txt+=navigator.plugins[i].name + "<br/>";
}
document.getElementById("example").innerHTML=txt;
</script>
</body>
</html>
回答by limc
You could try this: http://www.sliceratwork.com/detect-installed-browser-plugins-using-javascript
你可以试试这个:http: //www.sliceratwork.com/detect-installed-browser-plugins-using-javascript
... but this is not going to detect browser add-ons like firebug, noscript, etc.
...但这不会检测浏览器加载项,如 firebug、noscript 等。
That script seems to detect only the following plugins:-
该脚本似乎只检测到以下插件:-
- Java
- 3D Markup Language for Web
- DjVu
- Flash
- Google Talk
- Acrobat Reader
- QuickTime
- RealPlayer
- SVG Viewer
- Shockwave
- Silverlight
- Skype
- VLC
- Windows Media Player
- Xara
- 爪哇
- 用于 Web 的 3D 标记语言
- 音乐录影带
- 闪光
- 谷歌谈话
- 爱看阅读器
- 快速时间
- 真实播放器
- SVG 查看器
- 冲击波
- 银光
- Skype
- VLC
- Windows媒体播放器
- 夏拉
回答by Canadian
This code will give you all the info you need:
此代码将为您提供所需的所有信息:
<HTML>
<HEAD>
<TITLE>About Plug-ins</TITLE>
</HEAD>
<BODY>
<SCRIPT language="javascript">
numPlugins = navigator.plugins.length;
if (numPlugins > 0)
document.writeln("Installed plug-ins");
else
document.writeln("No plug-ins are installed.");
for (i = 0; i < numPlugins; i++) {
plugin = navigator.plugins[i];
document.write("<center><font size=+1><b>");
document.write(plugin.name);
document.writeln("</b></font></center><br>");
document.writeln("<dl>");
document.writeln("<dd>File name:");
document.write(plugin.filename);
document.write("<dd><br>");
document.write(plugin.description);
document.writeln("</dl>");
document.writeln("<p>");
document.writeln("<table border=1 >");
document.writeln("<tr>");
document.writeln("<th width=20%>Mime Type</th>");
document.writeln("<th width=50%>Description</th>");
document.writeln("<th width=20%>Suffixes</th>");
document.writeln("<th>Enabled</th>");
document.writeln("</tr>");
numTypes = plugin.length;
for (j = 0; j < numTypes; j++)
{
mimetype = plugin[j];
if (mimetype){
enabled = "No";
enabledPlugin = mimetype.enabledPlugin;
if (enabledPlugin && (enabledPlugin.name == plugin.name))
enabled = "Yes";
document.writeln("<tr align=center>");
document.writeln("<td>");
document.write(mimetype.type);
document.writeln("</td>");
document.writeln("<td>");
document.write(mimetype.description);
document.writeln("</td>");
document.writeln("<td>");
document.write(mimetype.suffixes);
document.writeln("</td>");
document.writeln("<td>");
document.writeln(enabled);
document.writeln("</td>");
document.writeln("</tr>");
}
}
document.write("</table>");
}
</SCRIPT>
</BODY>
</HTML>