remove

  • Revision slug: Extensions/Mobile/API/NativeWindow/contextmenus/remove
  • Revision title: remove
  • Revision id: 295808
  • Created:
  • Creator: wbamberg
  • 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.contextmenus.add() adds an item to the context menu in Firefox for Android, returning an ID for the item. To remove the item, use NativeWindow.contextmenus.remove(), passing in the item's ID.

Syntax

window.NativeWindow.contextmenus.remove(menuID);

menuID
The ID of the item to remove.

Example

The following example adds a new context menu item, stores the ID returned by add(), and later uses that ID to remove the item:

var menuID;  
      
function loadIntoWindow(window) {      
  if (!window)      
    return;  
  let label = "Show HTML";  
  let selector =  window.NativeWindow.contextmenus.SelectorContext("*");  
  menuID = window.NativeWindow.contextmenus.add(label, selector, function(target) {        
    window.NativeWindow.toast.show(target.outerHTML, "short");         
  });      
}      
         
function unloadFromWindow(window) {      
  if (!window)      
    return;      
  window.NativeWindow.contextmenus.remove(menuID);        
}

See Also

Revision Source

<div class="note">
  The <a href="/en/Extensions/Mobile/API/NativeWindow" title="https://developer.mozilla.org/en/DOM/window.NativeWindow">NativeWindow</a> 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><a href="/en/Extensions/Mobile/API/NativeWindow/contextmenus" title="en/DOM/window.NativeWindow.contextmenus">NativeWindow.contextmenus</a>.add() </code>adds an item to the context menu in <a href="/en/Mozilla/Firefox_for_Android" title="https://developer.mozilla.org/en/Mozilla/Firefox_for_Android">Firefox for Android</a>, returning an ID for the item. To remove the item, use <code>NativeWindow.contextmenus.remove()</code>, passing in the item's ID.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<p><code><em>window.NativeWindow.contextmenus.remove</em><em>(menuID);</em></code></p>
<dl>
  <dt>
    <code>menuID</code></dt>
  <dd>
    The ID of the item to remove.</dd>
</dl>
<h2 id="Example" name="Example">Example</h2>
<p>The following example adds a new context menu item, stores the ID returned by <code>add()</code>, and later uses that ID to remove the item:</p>
<pre class="brush: js">
var menuID; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
function loadIntoWindow(window) {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; if (!window)&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp; return; &nbsp;
&nbsp; let label = "Show HTML"; &nbsp;
&nbsp; let selector =&nbsp; window.NativeWindow.contextmenus.SelectorContext("*"); &nbsp;
&nbsp; menuID = window.NativeWindow.contextmenus.add(label, selector, function(target) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp; window.NativeWindow.toast.show(target.outerHTML, "short");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; });&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
}&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
function unloadFromWindow(window) {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; if (!window)&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp; return;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; window.NativeWindow.contextmenus.remove(menuID);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
}
</pre>
<h2 id="Specification" name="Specification">See Also</h2>
Revert to this revision