问题
Once the require("sdk/panel").Panel
code is enabled, I cannot find the addone button, even cannot find it in customize page, what's wrong?
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);
}
回答1:
The reason is this line :
var data = require("sdk/panel").data;
but you should write :
data = require("sdk/self").data;
as require("sdk/panel") has no "data", the variable became undefined. Later, when you call data.url("okentry.html"), browser throws exception and Panel constructor and all code below is not executed.
来源:https://stackoverflow.com/questions/29710818/why-the-addone-button-is-lost-when-i-enable-panel-code