简体   繁体   English

扩展和插件之间的通信

[英]Communication between extension and plugin

I have written a Firefox extension which queries some browser information. 我写了一个Firefox扩展,查询一些浏览器信息。 I need to send this information to an NPAPI plugin from my extension. 我需要将此信息发送到我的扩展程序中的NPAPI插件。

How can I achieve this? 我怎样才能做到这一点? Is there any way to communicate between NPAPI plugins and the extension's JavaScript code? 有没有办法在NPAPI插件和扩展的JavaScript代码之间进行通信? I am grateful for any useful links or code snippets. 我很感激任何有用的链接或代码片段。

If the plugin provides a scripting interface , the extension can just call its functions when wants to send the information. 如果插件提供脚本接口 ,则扩展可以在想要发送信息时调用其功能。

You need to have access to the plugin element, eg: 您需要访问插件元素,例如:

  • var plug = someDocument.getElementById('yourPluginId');
  • or by finding the embed / object elements you want without a specific ID 或者通过在没有特定ID的情况下查找所需的embed / object元素

To find the elements without having a specific id , you could eg collect them using XPath or by using getElementsByTagName() . 要查找没有特定id的元素,您可以使用XPath或使用getElementsByTagName()来收集它们。
Keep in mind that the mime type might not necessarily identify your plugin if you are not using one specific to your plugin. 请记住,如果您没有使用特定于插件的插件,则mime类型可能不一定标识您的插件。 You might need to check custom plugin name/version information in addition to the type attribute. 除了type属性之外,您可能还需要检查自定义插件名称/版本信息。

Once you have the plugin element you can simply call functions on it from JavaScript (eg plug.someFunction(someData); ). 一旦你有了插件元素,你就可以从JavaScript调用函数(例如plug.someFunction(someData); )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM