Skip to content Skip to sidebar Skip to footer

Automatically Install Toolbarbutton To Firefox Nav-bar, Not Working With Insertitem

So I've read just about everything I could find on MDN, stackoverflow, etc, and it all seems to be outdated and/or not working. Here is the issue: I want to automatically put my e

Solution 1:

Alright, like I thought, there was nothing wrong with my code, and the problem was exactly as I described.

When the extension is loaded and the script to install the button is executed, it's done too early. At the time of execution, "currentSet" only contains the default buttons. No other extension buttons are loaded yet. As a result, if you modify the currentSet and save (persist) it, you wipe out all other buttons.

The solution (for me) was to force my "install" script to wait longer. I found that once the page had been loaded, all of the other buttons had enough time to appear. So, I simply did this:

functioninstallButton() {

    var navbar = document.getElementById("nav-bar");
    var newset = navbar.currentSet + ",MYBUTTONID";
    navbar.currentSet = newset;
    navbar.setAttribute("currentset", newset );
    document.persist("nav-bar", "currentset");

}

window.addEventListener("load", function () { installButton(); }, false);

Solution 2:

well I use this code to add toolbar button in navbar, but this works only for the first time for the fresh installation and not for the next installation i.e. upgrading of the addon as user can move/drag the icon to different location. So, you need to try this in the new firefox profile. Here is the code:

//plcae toolbar iconvar navbar = document.getElementById("nav-bar");
var newset = navbar.currentSet + ",MYBUTTON_ID";
navbar.currentSet = newset;
navbar.setAttribute("currentset", newset );
document.persist("nav-bar", "currentset"); 

and here is the code for XUL Overlay:

<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="MYBUTTON_ID" inserbefore="searchBar" class="toolbarbutton-1 chromeclass-toolbar-additional"
    label="MYBUTTON_ID" tooltiptext="MYBUTTON_ID"
    onclick="MYBUTTON_ID()"/>
</toolbarpalette>

or you can force the icon to display in nav bar against user will, this will take effect after each firefox restart, however not recommended

var navbar = document.getElementById("nav-bar");

    var newset = navbar.currentSet;
    if (newset.indexOf("MYBUTTON_ID") == -1)
    {
        if (newset.indexOf("reload-button,stop-button,") > -1)
            newset = newset.replace("reload-button,stop-button,", "reload-button,stop-button,MYBUTTON_ID,");
        else
            newset = newset + ",MYBUTTON_ID";
        navbar.currentSet = newset;
        navbar.setAttribute("currentset", newset );
        document.persist("nav-bar", "currentset"); 
    }

Post a Comment for "Automatically Install Toolbarbutton To Firefox Nav-bar, Not Working With Insertitem"