window.NativeWindow.doorhanger

This article is in need of a technical review.

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.doorhanger object, which can be used to display doorhanger notifications (also known as popup notifications) on Firefox for Android.

Doorhanger notifications provide a way to present decisions to users that is less intrusive than a modal dialog. You can display a doorhanger using NativeWindow.doorhanger.show(). On Firefox for Android a doorhanger displays a title and an array of buttons for the user choices: selecting a button calls the corresponding callback function. Doorhangers are attached to a specific tab, and you can control the doorhanger's persistence.

You can close a doorhanger explicitly using NativeWindow.doorhanger.hide().

Example

In the example below, an add-on adds a new menu item labeled "Offer cake" which constructs and shows a new doorhanger when selected.

The doorhanger contains two buttons, which just show different toast messages when selected.NativeWindow-doorhanger.png

var menuID;

function offerCake(window) {
  let buttons = [
    {
      label: "Yes, please!",
      callback: function () {
        window.NativeWindow.toast.show("yum", "short");
      }
    },
    {
      label: "Not today",
      callback: function () {
        window.NativeWindow.toast.show("still hungry", "short");
      }
    }
  ];

  let message = "How about some cake?";
  let options = {
    persistence: 1
  };

  window.NativeWindow.doorhanger.show(message, "cake-request", buttons, window.BrowserApp.selectedTab.id, options);
}

function loadIntoWindow(window) {
  if (!window)
    return;
  menuID = window.NativeWindow.menu.add("Offer cake", null, function(){  
    offerCake(window);   
  });
}

function unloadFromWindow(window) {
  if (!window)
    return;
  window.NativeWindow.menu.remove(menuID);  
}

Methods

show
Show a doorhanger notification.
hide
Hide a doorhanger notification.

See also

Attachments

File Size Date Attached by
NativeWindow-doorhanger.png
170879 bytes 2012-06-20 19:29:44 wbamberg

Document Tags and Contributors

Contributors to this page: wbamberg, kscarfone
Last updated by: wbamberg,