Mobile/Fennec/Extensions/UserInterface/Site Menu

From MozillaWiki
Jump to: navigation, search


The site menu is displayed when a user taps on the favicon (or Site Identity button) next the address bar. It's purpose is to provide more detail and options related to the page the user is viewing.

By default it shows security information, controls to add a search providers and clear site-specific preferences, and commands to share, save, or find within the page.

Adding to the Site Menu

Add-ons can use the site panel to display additional information or actions related to the current page.

To add a command to the site menu, add a pageaction element to the #pageactions-container box. For example, in a XUL overlay you could write:

 <hbox id="pageactions-container">
   <pageaction id="sayhello-action"
     title="Say Hello"
     description="Display a greeting" <!-- Description is optional -->

Changing Site Menu items

New in Fennec 2.0: If you want to enable, disable, or change your pageaction, you can register a method to be called each time the menu appears. Use the PageActions.register function:

PageActions.register(id, callback, thisObject); // Requires Fennec 2.0a1 or higher.
The ID of your pageaction element. (Remember, your IDs should include a string that is unique to your add-on, to avoid conflicting with Fennec code or other add-ons.)
A function that takes a pageaction element and returns a boolean: true if the pageaction should be visible, false if it should be hidden.
(optional) An object to use as "this" in the callback function.


PageActions.register("sayhello-action", function(element) {
  // Hide the menu item if we're in a blank tab.
  if (getBrowser().currentURI == "about:blank")
    return false;

  // Change the pageaction title.
  element.setAttribute("title", "Say hello to " + getBrowser().contentTitle);

  return true;

Sample Code