启用require("sdk/panel").Panel
代码后,我找不到addone按钮,即使在自定义页面中找不到它,有什么问题?
var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var data = require("sdk/panel").data;
// var okentry=require("sdk/panel").Panel({
// contentURL: data.url("okentry.html"),
// contentScriptFile: data.url("okentry.js")
// });
var button = buttons.ActionButton({
id: "test-panel",
label: "ok",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
function handleClick(state) {
tabs.open("https://www.baidu.com/");
// okentry.show();
alert('hi');
console.info(tabs.length);
}
答案 0 :(得分:2)
原因是这一行:
var data = require("sdk/panel").data;
但你应该写:
data = require("sdk/self").data;
as require(“sdk / panel”)没有“数据”,变量变为未定义。稍后,当您调用data.url(“okentry.html”)时,浏览器会抛出异常,并且Panel构造函数和下面的所有代码都不会被执行。