Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

This article needs a technical review. How you can help.

The NativeWindow object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

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:

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:NativeWindow-menu.png

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).

See also

Document Tags and Contributors

 Contributors to this page: wbamberg, paa, wesj, kscarfone, sriramramani, gregg.lind
 Last updated by: wbamberg,