Technology area | Safari Extensions |
Availability | Available in Safari 5.0 and later. |
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.
Returns a list of the context menu items from this extension.
readonly attribute array contextMenuItems
Only menu items from your extension are returned.
Appends a menu item to the contextual menu.
SafariExtensionContextMenuItem appendContextMenuItem (in DOMString identifier, in DOMString title, in DOMString command);
The unique identifier of the menu item.
The title of the menu item.
The command identifier that the context menu item sends when activated. Optional.
The context menu item that was appended.
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.
Inserts a menu item at a specific index in the contextual menu.
SafariExtensionContextMenuItem insertContextMenuItem (in unsigned int index, in DOMString identifier, in DOMString title, in DOMString command);
The index where the menu item is being inserted.
The unique identifier of the menu item.
The title of the menu item.
The command identifier that the context menu item sends when activated. Optional.
The context menu item that was inserted.
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.
Last updated: 2010-06-29