darkoshi: (Default)
I'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:
    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.

December 2025

S M T W T F S
 12345 6
78 910111213
14151617181920
2122 23 24252627
28 293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Thursday, January 1st, 2026 05:29 pm
Powered by Dreamwidth Studios