SafariExtensionMenu Class Reference

Technology area
Safari Extensions
Availability
Available in Safari 5.1 and later.

Overview

The SafariExtensionMenu class represents menus.

Tasks

Working with Menus

Adding Menu Items

Removing Menu Items

Properties

identifier

The unique identifier of the menu.

readonly attribute DOMString identifier
Availability

menuItems

The items in the menu.

readonly attribute array menuItems
Availability

visible

A Boolean value that indicates whether the menu is currently visible to the user.

readonly attribute boolean visible
Discussion

Changes made to the menu while it is visible to the user are not reflected until the next time it is shown. If the user selects a menu item that was removed after the menu became visible, the menu item’s command is not sent.

Availability

Methods

appendMenuItem

Creates a menu item and appends it to the menu.

SafariExtensionMenuItem appendMenuItem (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 to send when the menu item is activated. This parameter is optional; the default value is the menu item’s identifier.

Return Value

The menu item that was appended.

Discussion

If a menu item with the same identifier already exists, it is removed from before appending the menu item.

Availability
  • Available in Safari 5.1 and later.

appendSeparator

Creates a separator menu item and appends it to the menu.

SafariExtensionMenuItem appendSeparator (in DOMString identifier);
Parameters
identifier

The unique identifier of the menu item.

Return Value

The menu item that was appended.

Discussion

If a menu item with the same identifier already exists, it is removed from before appending the separator.

Availability
  • Available in Safari 5.1 and later.

insertMenuItem

Creates a menu item and inserts it in the menu at the given index.

SafariExtensionMenuItem insertMenuItem (in unsigned int index, in DOMString identifier, in DOMString title, in DOMString command);
Parameters
index

The index at which the menu item is being inserted.

identifier

The unique identifier of the menu item being inserted.

title

The title of the menu item.

command

The command identifier to send when the menu item is activated. This parameter is optional; the default value is the menu item’s identifier.

Return Value

The menu item that was inserted.

Discussion

If a menu item with the same identifier already exists, it is removed from before inserting the menu item.

If the value of index is NaN, Infinity, a negative number, or a number greater than the number of items in the menu, the menu item is appended at the end of the menu.

Availability
  • Available in Safari 5.1 and later.

insertSeparator

Creates a separator menu item and inserts it in the menu at the given index.

SafariExtensionMenuItem insertSeparator (in unsigned int index, in DOMString identifier);
Parameters
index

The index at which the menu item is being inserted.

identifier

The unique identifier of the menu item being inserted.

Return Value

The menu item that was inserted.

Discussion

If a menu item with the same identifier already exists, it is removed from before inserting the separator.

If the value of index is NaN, Infinity, a negative number, or a number greater than the number of items in the menu, the separator is appended at the end of the menu.

Availability
  • Available in Safari 5.1 and later.

removeMenuItem

Removes a menu item.

void removeMenuItem (in unsigned int index);
Parameters
index

The index of the menu item being removed.

Discussion

Invalid indexes are ignored.

Availability
  • Available in Safari 5.1 and later.