使用扩展程序的工具栏项时收到通知的最佳方式是什么?
我想在使用 toolbaritem
时设置 label
属性和事件侦听器。因为即使我将扩展程序的 toolbaritem
添加到
,document.getElementById
也找不到它,除非它正在使用中。目前,我在导航栏和附加栏上有 DOMNodeInserted
事件侦听器,用于设置我的 toolbaritem
的属性,但我想知道是否有更好的方式?
I want to setup label
attributes, and event listeners for a toolbaritem
when it's being used. Because even though I add my extension's toolbaritem
to <toolbarpalette id="BrowserToolbarPalette">
it is not found by document.getElementById
unless it is being used. At the moment I have DOMNodeInserted
event listeners on the navigation bar and add-on bar which sets up my toolbaritem
's attributes, but I'm wondering if there is a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否太早调用
document.getElementById
(可能在 Firefox 将项目添加到工具栏中之前)?如果是这样,您可能希望将代码移动到注册为在主浏览器窗口上的"load"
事件上调用的函数。这应该确保在代码运行时浏览器(包括工具栏)已成功构建。Are you calling
document.getElementById
too early, possibly before Firefox has added the item into the toolbar? If so, you might want to move your code to a function which is registered to be called on the"load"
event on the main browser window. This should ensure that the browser, including the toolbar, has been successfully built by the time your code runs.请查看广播者和观察者。我想这会对你有帮助。
Have a look at Broadcasters and Observers. I think this will help you.