在运行时更改 Firefox addon sdk 工具栏按钮图标

发布于 2025-01-05 04:18:49 字数 389 浏览 4 评论 0原文

我正在使用工具栏按钮库,因为如果我重新启动 Firefox,普通的小部件将不会存储它们的位置。 不幸的是我想在运行时更改图标。使用我尝试过的小部件:

widget.contentURL = "http://127.0.0.1:8082/static/icons/eth_16.png";

使用我尝试过的工具栏按钮:

Toolbarbutton.image = "http://127.0.0.1:8082/static/icons/eth_16.png";

没有任何效果。该图像似乎仅在构造工具栏按钮时使用。

还尝试销毁并使用不同的图标重新创建按钮,但这会导致烦人的闪烁。

任何想法将不胜感激。

I'm using the toolbarbutton library, because the normal widgets would not store their positions if I restart Firefox.
Unfortunately I want to change the icon on runtime. With the widgets I did:

widget.contentURL = "http://127.0.0.1:8082/static/icons/eth_16.png";

With the toolbarbuttons I tried:

Toolbarbutton.image = "http://127.0.0.1:8082/static/icons/eth_16.png";

without any effect. The image seems to be only used when construction the toolbarbutton.

Also tried to destroy and recreate the button with a different icon, but that causes annoying flickering.

Any idea would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风柔一江水 2025-01-12 04:18:49

我做了一个快速测试,这应该按预期工作,所以我不确定您在这里遇到了什么问题。下面是一些运行良好的示例代码:

var toolbarbutton = require("toolbarbutton");
var timer = require("timer");

var TEST_ICON_M_URL = "http://www.mozilla.org/media/img/favicon.png";
var TEST_ICON_G_URL = "http://www.google.com//images/google_favicon_128.png";
console.log("TEST_ICON_URL", TEST_ICON_M_URL);

var options = {
  id: "test-tbb",
  label: "TEST BUTTON",
  toolbarID: "nav-bar",
  image: TEST_ICON_M_URL,
  forceMove: true
};

var tbb = toolbarbutton.ToolbarButton(options);
tbb.moveTo(options);

timer.setTimeout(function () {
  tbb.image = TEST_ICON_G_URL;
  console.log("switched", TEST_ICON_G_URL);
}, 5 * 1000); // 5 seconds

您可以发布更多代码吗?问题一定出在其他地方。

I did a quick test and this should work as expected so I'm not sure what issue you're running into here. Here's some example code that works just fine:

var toolbarbutton = require("toolbarbutton");
var timer = require("timer");

var TEST_ICON_M_URL = "http://www.mozilla.org/media/img/favicon.png";
var TEST_ICON_G_URL = "http://www.google.com//images/google_favicon_128.png";
console.log("TEST_ICON_URL", TEST_ICON_M_URL);

var options = {
  id: "test-tbb",
  label: "TEST BUTTON",
  toolbarID: "nav-bar",
  image: TEST_ICON_M_URL,
  forceMove: true
};

var tbb = toolbarbutton.ToolbarButton(options);
tbb.moveTo(options);

timer.setTimeout(function () {
  tbb.image = TEST_ICON_G_URL;
  console.log("switched", TEST_ICON_G_URL);
}, 5 * 1000); // 5 seconds

Is there more code you could post? The problem must be somewhere else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文