我正在使用SDK Tutorial网站中的代码:
var sidebar = require("sdk/ui/sidebar").Sidebar({
id: 'my-sidebar',
title: 'My Sidebar',
url: require("sdk/self").data.url("sidebar.html"),
onAttach: function (worker) {
// listen for a "ready" message from the script
worker.port.on("ready", function() {
// send an "init" message to the script
worker.port.emit("init", "message from main.js");
});
}
});
Run Code Online (Sandbox Code Playgroud)
这非常有效.现在的问题是,这只允许我通过work.port onAttach发送一些东西(以及侧栏上的3个其他事件).我需要的是使用此侧栏范围之外的emit函数.例如,如果我在同一个main.js中使用一个类似于标签的监听器
tabs.on('ready', function(tab) {
sidebar.worker.port.emit("init", "message from main.js");
}
Run Code Online (Sandbox Code Playgroud)
这不起作用.我也试过了
sidebar.port.emit("init", "message from main.js");
Run Code Online (Sandbox Code Playgroud)
要么
worker.port.emit("init", "message from main.js");
Run Code Online (Sandbox Code Playgroud)
没有成功.
我也尝试将标签监听器放在侧边栏的onAttach中(所以监听器内部是一个监听器),但这也无效.
有人对那个有想法吗?谢谢.
javascript firefox firefox-addon firefox-sidebar firefox-addon-sdk