【发布时间】:2012-01-03 19:00:22
【问题描述】:
我有一个覆盖overlay.xul 的文件,它覆盖了browser.xul。我想以与 chrome 扩展中实现的方式类似的方式实现消息传递。
chrome.manifest-
content helloworld content/
overlay chrome://browser/content/browser.xul chrome://helloworld/content/overlay.xul
overlay chrome://navigator/content/navigator.xul chrome://helloworld/content/overlay.xul
skin helloworld classic/1.0 skin/
style chrome://global/content/customizeToolbar.xul chrome://helloworld/content/overlay.css
我如何注册content_script.js,在我的例子中是overlay.js?
Overlay.xul -
<script type="application/x-javascript" src="chrome://helloworld/content/jquery.js" />
<script type="application/x-javascript" src="chrome://helloworld/content/overlay.js" />
<script type="application/x-javascript" src="chrome://helloworld/content/background.js" />
现在在我的overlay.js 中,我正在使用 -
document.documentElement.addEventListener('click', function(e) {
messageManager.sendAsyncMessage('MyMessenger.MyMessage', {});
}, true);
而background.js 是-
addMessageListener("MyMessenger.MyMessage", function(obj) {
Firebug.Console.log(obj.name);
}, true);
- 消息传递的正确语法是什么?
- 如何配置内容脚本和浏览器脚本的连接?
【问题讨论】:
标签: firefox firefox-addon message-passing