diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/navigatorplugins/plugins | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/navigatorplugins/plugins')
-rw-r--r-- | files/zh-cn/web/api/navigatorplugins/plugins/index.html | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/navigatorplugins/plugins/index.html b/files/zh-cn/web/api/navigatorplugins/plugins/index.html new file mode 100644 index 0000000000..9953dd916e --- /dev/null +++ b/files/zh-cn/web/api/navigatorplugins/plugins/index.html @@ -0,0 +1,95 @@ +--- +title: NavigatorPlugins.plugins +slug: Web/API/NavigatorPlugins/plugins +tags: + - API + - DOM + - Navigator + - NavigatorPlugins + - Reference +translation_of: Web/API/NavigatorPlugins/plugins +--- +<p>{{APIRef("HTML DOM")}}</p> + +<p>返回一个 {{ domxref("PluginArray") }} 类型的对象, 包含了当前所使用的浏览器安装的所有插件。</p> + +<div class="blockIndicator note"> +<p>在Firefox 29及之后的版本,出于隐私考虑,<code>navigator.plugins</code> 数组的枚举可能会被限制。如果一定要检查是否存在某个浏览器插件,应该用准确的插件名字查询 <code>navigator.plugins</code> 或 {{DOMxRef("navigator.mimeTypes")}} ,而不是枚举 <code>navigator.plugins</code> 数组,再对比每个插件的名字。 这项有关隐私的改变不会禁用任何插件,只是将插件名字从枚举中隐藏了而已。</p> +</div> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="eval"><em>plugins</em> = navigator.plugins; +</pre> + +<p><code>plugins</code> 是一个 {{DOMxRef("PluginArray")}} 对象,通过名字或项目列表获取 {{DOMxRef("Plugin")}} 对象。</p> + +<p>返回值不是一个普通的JavaScript数组,但是它也有 <code>length</code> 属性,也可以使用<code>plugins</code>[<code><em>index</em></code>]来获取到每个元素的值, 例如(<code>plugins{{ mediawiki.external("2") }}</code>), 效果和使用 <code>item(<em>index</em>)</code> 以及 <code>namedItem(<em>"name"</em>)</code> 是一样的.</p> + +<h2 id="Example" name="Example">示例</h2> + +<p>下述示例中的函数返回Shockwave Flash插件的版本。</p> + +<pre>function getFlashVersion() { + var flash = navigator.plugins.namedItem('Shockwave Flash'); + if (typeof flash != 'object') { + // flash is not present + return undefined; + } + if(flash.version){ + return flash.version; + } else { + //No version property (e.g. in Chrome) + return flash.description.replace(/Shockwave Flash /,""); + } +} +</pre> + +<p>下述示例可显示已安装插件的信息。</p> + +<pre>var pluginsLength = navigator.plugins.length; + +document.body.innerHTML = pluginsLength + " Plugin(s)<br>" + + '<table id="pluginTable"><thead>' + +'<tr><th>Name</th><th>Filename</th><th>description</th><th>version</th></tr>' + +'</thead><tbody></tbody></table>'; + +var table = document.getElementById('pluginTable'); + +for(var i = 0; i < pluginsLength; i++) { + let newRow = table.insertRow(); + newRow.insertCell().textContent = navigator.plugins[i].name; + newRow.insertCell().textContent = navigator.plugins[i].filename; + newRow.insertCell().textContent = navigator.plugins[i].description; + newRow.insertCell().textContent = navigator.plugins[i].version?navigator.plugins[i].version:""; +} +</pre> + +<h2 id="Notes" name="Notes">备注</h2> + +<p>{{DOMxRef("Plugin")}}对象提供一个小型接口,用于获取浏览器中安装的各种插件的信息。你也可以进入 <code>about:plugins</code> 页面,来查看浏览器上安装的插件(Chrome已移除该入口)。</p> + +<h2 id="规范">规范</h2> + +<table> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-navigator-plugins', 'NavigatorPlugins.plugins')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{Compat("api.NavigatorPlugins.plugins")}}</p> + +<p>In addition to listing each plugin as a pseudo-array by zero-indexed numeric properties, Firefox provides properties that are the plugin name directly on the <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/API/PluginArray">PluginArray</a> object.</p> |