window.NativeWindow.doorhanger.show

« DOM Reference

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

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.doorhanger.show() displays a doorhanger attached to a Firefox for Android tab.

Syntax

NativeWindow.doorhanger.show(message, value, buttons, tabID, options);

message
The message displayed in the doorhanger.
value

This is a string-based tag for the doorhanger, used as an argument to NativeWindow.doorhanger.hide().

buttons
This is an array of button objects, once for each choice to offer the user. Each button has two attributes:
  • label: a string to display on the button
  • callback: a function that will be called when the button is selected
tabID

The ID of the tab the doorhanger should be attached to. You can retrieve the tabID using the BrowserApp object: for example, window.BrowserApp.selectedTab.id returns the ID of the active tab.

options
Additional options for the doorhanger. Two options are currently defined:
  • timeout: a time in milliseconds. The notification will not automatically dismiss before this time.
  • persistence: an integer. The notification will not automatically dismiss for this many page loads. If persistence is set to -1, the doorhanger will never automatically dismiss.

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.

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

See Also

Document Tags and Contributors

Last updated by: wbamberg,
Hide Sidebar