Safari Developer Library

Developer

SafariExtensionContextMenu Class Reference

Options
Deployment Target:

On This Page

SafariExtensionContextMenu

Instances of the SafariExtensionContextMenu class represent a contextual menu that is populated by the extension. Safari displays the contents of this menu as part of its contextual menu.

Each time a contextual menu is about to be displayed, Safari creates a new menu, populated with the default menu items from your extension’s Info.plist file. Next, a SafariExtensionContextMenuEvent event is sent, and its listeners add menu items to the menu. Then a SafariExtensionContextMenuItemValidateEvent is sent for each menu item, and its listeners have the opportunity to prevent items in the context menu from being displayed by marking them as disabled.

Your extension has access only to context menu items that it has added; there is no way to change or count menu items from Safari or other extensions. Therefore, it is important to limit the menu items that your extension adds to a reasonable number, to avoid displaying an unusably long contextual menu.

Inheritance


  • SafariExtensionContextMenu

Conforms To


Not Applicable

Import Statement


Not Applicable Not Applicable

Availability


Available in Safari 5.0 and later.
  • Appends a menu item to the contextual menu.

    Declaration

    JavaScript

    SafariExtensionContextMenuItem appendContextMenuItem (in DOMString identifier, in DOMString title, in DOMString command);

    Parameters

    identifier

    The unique identifier of the menu item.

    title

    The title of the menu item.

    command

    The command identifier that the context menu item sends when activated. Optional.

    Return Value

    The context menu item that was appended.

    Discussion

    If another menu item with the same identifier already exists, it is removed before appending the menu item. If command is not supplied, identifier is used as the command identifier.

    Availability

    Available in Safari 5.0 and later.

  • Inserts a menu item at a specific index in the contextual menu.

    Declaration

    JavaScript

    SafariExtensionContextMenuItem insertContextMenuItem (in unsigned int index, in DOMString identifier, in DOMString title, in DOMString command);

    Parameters

    index

    The index where the menu item is being inserted.

    identifier

    The unique identifier of the menu item.

    title

    The title of the menu item.

    command

    The command identifier that the context menu item sends when activated. Optional.

    Return Value

    The context menu item that was inserted.

    Discussion

    If another menu item with the same identifier already exists, it is removed before appending the menu item. If command is not supplied, identifier is used as the command identifier.

    Availability

    Available in Safari 5.0 and later.

  • contextMenuItems Property

    Returns a list of the context menu items from this extension.

    Declaration

    JavaScript

    readonly attribute array contextMenuItems

    Discussion

    Only menu items from your extension are returned.

    Availability

    Available in Safari 5.0 and later.