SeaMonkey - adding button to navigation toolbar
Monday, September 26th, 2011 12:43 amI've been updating my Firefox/SeaMonkey add-on.
One thing I wanted, was for the add-on to automatically add the "Toggle Colors" button to the navigation toolbar when the add-on is installed, so that the user doesn't have to manually do it.
I was using the code from this page:
https://developer.mozilla.org/en/Code_snippets/Toolbar
It worked on Firefox, but not on SeaMonkey.
The code on that page has a condition to avoid adding the button, if it is already there.
For Firefox, document.getElementById(id) returns null when the button isn't on the toolbar yet. But for SeaMonkey, it isn't null... the button is already in the document, but not on the toolbar. The button is on "BrowserToolbarPallette", which apparently is in the document for SeaMonkey, but not for Firefox.
I updated the code as follows, so that it would work for both Firefox and SeaMonkey.
Instead of using this condition at the start of the function:
I had to use this:
I also had to slightly change the code to remove the "let" keyword, which didn't work in my browser.
One thing I wanted, was for the add-on to automatically add the "Toggle Colors" button to the navigation toolbar when the add-on is installed, so that the user doesn't have to manually do it.
I was using the code from this page:
https://developer.mozilla.org/en/Code_snippets/Toolbar
It worked on Firefox, but not on SeaMonkey.
The code on that page has a condition to avoid adding the button, if it is already there.
For Firefox, document.getElementById(id) returns null when the button isn't on the toolbar yet. But for SeaMonkey, it isn't null... the button is already in the document, but not on the toolbar. The button is on "BrowserToolbarPallette", which apparently is in the document for SeaMonkey, but not for Firefox.
I updated the code as follows, so that it would work for both Firefox and SeaMonkey.
Instead of using this condition at the start of the function:
if (!document.getElementById(id))
I had to use this:
var button; button = document.getElementById(id); if (!button || button.parentNode.id == "BrowserToolbarPalette") // need this for SeaMonkey { ... }
I also had to slightly change the code to remove the "let" keyword, which didn't work in my browser.