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.

May 2025

S M T W T F S
    123
45678910
11121314151617
1819 2021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Thursday, May 22nd, 2025 09:38 pm
Powered by Dreamwidth Studios