Why the addone button is lost when I enable panel code?

亡梦爱人 提交于 2020-02-06 11:22:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!