mozilla

Revision 376565 of add

  • Revision slug: Extensions/Mobile/API/NativeWindow/menu/add
  • Revision title: add
  • Revision id: 376565
  • Created:
  • Creator: sriramramani
  • Is current revision? No
  • Comment

Revision Content

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

NativeWindow.menu.add() adds a new item to the main menu in Firefox for Android.

Syntax

var menuID = window.NativeWindow.menu.add(name, icon, callback);

Returns

name
The string displayed by the menu item.
icon

An icon to display next to the item's name, specified as a file:// or data: URI. To add a menu item without an icon, supply null here.

callback
The function to be called when the item is selected. It is called with no arguments.
 
menuID
An identifier for the menu item. This may be used to remove the item using NativeWindow.menu.remove().

Example

The following example adds a menu item with the name "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("Show Toast", null, function(){  
    showToast(window);   
  });  
}  
 
function removeMenuItem(window) {  
  window.NativeWindow.menu.remove(menuID);  
}

See Also

Revision Source

<div class="note">
  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.</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p><code>NativeWindow.menu.add()</code> adds a new item to the main menu in <a href="/en/Mozilla/Firefox_for_Android" title="https://developer.mozilla.org/en/Mozilla/Firefox_for_Android">Firefox for Android</a>.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<p><code><em>var menuID = window.NativeWindow.menu.add(name, icon, callback);</em></code></p>
<h3 id="Returns" name="Returns">Returns<span id="cke_bm_115S" style="display: none;"> </span></h3>
<dl>
  <dt>
    <code>name</code></dt>
  <dd>
    The string displayed by the menu item.</dd>
  <dt>
    <code>icon</code></dt>
  <dd>
    <p>An icon to display next to the item's name, specified as a <code>file://</code> or <code>data:</code> URI. To add a menu item without an icon, supply <code>null</code> here.</p>
  </dd>
  <dt>
    <code>callback</code></dt>
  <dd>
    The function to be called when the item is selected. It is called with no arguments.</dd>
  <dt>
    &nbsp;</dt>
  <dt>
    menuID</dt>
  <dd>
    An identifier for the menu item. This may be used to remove the item using <code>NativeWindow.menu.remove().</code><span id="cke_bm_115E" style="display: none;">&nbsp;</span></dd>
</dl>
<h2 id="Example" name="Example">Example</h2>
<p>The following example adds a menu item with the name "Show Toast," which displays a toast notification when clicked:</p>
<pre class="brush: js">
function showToast(window) { &nbsp;
&nbsp; window.NativeWindow.toast.show("Showing you a toast", "short"); &nbsp;
} &nbsp;
&nbsp;
var menuID; &nbsp;
&nbsp;
function addMenuItem(window) { &nbsp;
&nbsp; menuID = window.NativeWindow.menu.add("Show Toast", null, function(){ &nbsp;
&nbsp;&nbsp;&nbsp; showToast(window);&nbsp; &nbsp;
&nbsp; }); &nbsp;
} &nbsp;
&nbsp;
function removeMenuItem(window) { &nbsp;
&nbsp; window.NativeWindow.menu.remove(menuID); &nbsp;
}
</pre>
<h2 id="Specification" name="Specification">See Also</h2>
Revert to this revision