This article needs a technical review. How you can help.
Summary
Returns a reference to the NativeWindow.menu
object, which can be used to add items to the main Firefox for Android menu, and subsequently remove them. You can add a menu item to a browser window using NativeWindow.menu.add()
and remove it using NativeWindow.menu.remove()
.
A common pattern is for a restartless add-on to add and remove menu items in the add-on's bootstrap.js
:
- from the
startup()
function, enumerate windows using nsIWindowMediator and add any menu items needed - from the
shutdown()
function, enumerate windows using nsIWindowMediator and remove any menu items added
This ensures that the item is always present while the add-on is installed and enabled, and that it is cleaned up properly when the add-on is uninstalled or disabled. But note that bootstrap.js
is not attached to a DOM window, so you need to get a window, for example using nsIWindowMediator, before you can use this pattern.
Example
The following example adds a menu item with the label "Show Toast", which displays a toast notification when clicked:
function showToast(window) { window.NativeWindow.toast.show("Showing you a toast", "short"); } var menuID;function addMenuItem(window) { menuID = window.NativeWindow.menu.add(
{name: "Show Toast",
icon: null,
callback: function(){
showToast(window);
}
});
}
function removeMenuItem(window) { window.NativeWindow.menu.remove(menuID); }
Methods
- add
- Add an item to the menu.
- remove
- Remove an item from the menu.
- update
- Update an item in the menu.
Attributes
Attribute | Type | Description |
toolsMenuID |
int |
Use this as the parent ID to add your menu item to the Tools menu (only shown on Android 3.0+. On earlier versions your menu item will just be added to the base menu). |