MenuItem.disabled
From Opera 15 onward, Opera 11 & 12’s extension format is no longer supported, and instead, we’ve switched to Chromium’s extension model. Check out our new documentation for developing extensions for Opera 15 and higher and start building your own extensions.
Description:
The disabled
attribute represents whether a menu item is visible in a context menu. If the value is false
(default), the menu item will be displayed and is clickable, whereas if the value is true
the item will not be displayed in the context menu.
Syntax:
Boolean false
Example:
In the following example, a menu item is created for translating the web page into English. The menu item is disabled (not visible) if the user's browser language is not set to English.
<!--
The configuration file ('config.xml').
-->
<?xml version='1.0' encoding='utf-8'?>
<widget xmlns="http://www.w3.org/ns/widgets">
...
<feature name="opera:contextmenus"/>
...
</widget>
//
// The background process (e.g. index.html)
//
if (opera.contexts.menu) {
var menu = opera.contexts.menu;
// Create a menu item properties object
var itemProps = {
title: 'Translate page into English',
onclick: function(event) {
doTranslate(event.pageURL);
}
}
if (window.navigator.browserLanguage.indexOf('en') != 0) {
itemProps.disabled = true;
}
// Create a menu item with the specified properties
var item = menu.createItem(itemProps);
// Add the menu item to the context menu
menu.addItem(item);
}
This article is licensed under a Creative Commons Attribution 3.0 Unported license.
Comments