mozilla

Revision 501257 of toast

  • Revision slug: Mozilla/Add-ons/Firefox_for_Android/API/NativeWindow/toast
  • Revision title: toast
  • Revision id: 501257
  • Created:
  • Creator: wbamberg
  • Is current revision? Yes
  • Comment Editorial RevisionExtensions/Mobile/API/NativeWindow/toast Mozilla/Add-ons/Firefox_for_Android/API/NativeWindow/toast

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

Returns a reference to the NativeWindow.toast object, which can be used to display toast notifications on Firefox for Android.

A toast notification is a message that appears on the screen for a set interval and then fades away. It does not accept user input.

You can display a toast using NativeWindow.toast.show(), supplying:

  • the message to display
  • a duration parameter that controls how long the toast should be displayed. This takes one of two values: short or long.

Example

In the example below, an add-on adds a menu item that displays a toast:NativeWindow-toast.png

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);  
}

Methods

show
Show a toast notification.

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">Summary</h2>
<p>Returns a reference to the <code><a href="/en/Extensions/Mobile/API/NativeWindow" title="https://developer.mozilla.org/en/DOM/window.NativeWindow">NativeWindow</a>.toast</code> object, which can be used to display <a class="link-https" href="https://developer.android.com/guide/topics/ui/notifiers/toasts.html" title="https://developer.android.com/guide/topics/ui/notifiers/toasts.html">toast notifications</a> on <a href="/en/Mozilla/Firefox_for_Android" title="en/Mozilla/Firefox_for_Android">Firefox for Android</a>.</p>
<p>A toast notification is a message that appears on the screen for a set interval and then fades away. It does not accept user input.</p>
<p>You can display a toast using <code>NativeWindow.toast.show()</code>, supplying:</p>
<ul>
  <li>the message to display</li>
  <li>a <code>duration</code> parameter that controls how long the toast should be displayed. This takes one of two values: <code>short</code> or <code>long</code>.</li>
</ul>
<h2 id="Example">Example</h2>
<p>In the example below, an add-on adds a menu item that displays a toast:<a href="/@api/deki/files/6338/=NativeWindow-toast.png" title="NativeWindow-toast.png"><img align="right" alt="NativeWindow-toast.png" class="internal rwrap" src="/@api/deki/files/6338/=NativeWindow-toast.png?size=webview" style="width: 338px; height: 550px;" /></a></p>
<pre class="brush: js">
function showToast(window) { &nbsp;
  window.NativeWindow.toast.show("Showing you a toast", "short"); &nbsp;
} &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
var menuID; &nbsp;
&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp; &nbsp;
function removeMenuItem(window) { &nbsp;
&nbsp; window.NativeWindow.menu.remove(menuID); &nbsp;
}
</pre>
<h2 id="Methods">Methods</h2>
<dl>
  <dt>
    <a href="/en/Extensions/Mobile/API/NativeWindow/toast/show" title="en/Extensions/Mobile/API/NativeWindow/toast/show">show</a></dt>
  <dd>
    Show a toast notification.</dd>
</dl>
<h2 id="See_also">See also</h2>
Revert to this revision