0

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?

000
  • 26,951
  • 10
  • 71
  • 101
erikvold
  • 15,988
  • 11
  • 54
  • 98

2 Answers2

-1

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.

Tim
  • 9,171
  • 33
  • 51
  • The document.getElementById call is in a "load" event listener, the item dne and this appears to be because the user needs to customize the toolbar and add it. – erikvold Oct 22 '10 at 18:38
-2

Have a look at Broadcasters and Observers. I think this will help you.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • I just read it, it doesn't appear to be helpful. It appears to describe how you can broadcast changes to multiple elements in a document, but I want to know when a toolbaritem is added to browser.xul, which seems to me to be a completely different problem. – erikvold Oct 23 '10 at 19:39
  • @Erik Vold: What event listeners do you want to add to the button? You said *which sets up my toolbaritem's attributes*. You could have the attributes and event handlers set on the broadcaster instead and let the toolbarbutton observe them. – Felix Kling Nov 24 '10 at 20:03
  • Thanks Felix, this is a better way to solve my problem for now, but doesn't answer my question. – erikvold Dec 04 '10 at 23:25
  • If you edit your response I'll change my vote (I can't otherwise..) – erikvold Dec 04 '10 at 23:26
  • @Erik Vold: I think the problem is to find the right timing ;) – Felix Kling Dec 28 '10 at 22:15