我想从contentScriptFile打开新标签,但我无法访问标签变量。
我在Firefox高级API中使用了tabs。
//index.js
var self = require("sdk/self");
var cm = require("sdk/context-menu");
var tabs = require("sdk/tabs");
cm.Item({
label: "Test",
contentScriptFile : self.data.url("script.js")
});
//script.js
self.on(
'click',
function (node, data) {
tabs.open('http://example.com/'); //Not work :-(
}
);
答案 0 :(得分:0)
解决了'onMessage'的问题
//index.js
var self = require("sdk/self");
var cm = require("sdk/context-menu");
var tabs = require("sdk/tabs");
var menuItem = cm.Item({
label: "Test",
context: cm.SelectionContext(),
//We can use contentScript for simple app
contentScriptFile: self.data.url("script.js"),
onMessage: function () {
tabs.open('http://example.com/');
}
});
//script.js
self.on("click", self.postMessage);