This documentation relates to Opera's now deprecated .oex Extension API framework for Opera versions <= 12.15 and also provided by our OEX2NEX shim library.
For the latest Opera Extensions API documentation for Opera versions > 12.15 please consult the latest Opera Extensions API documentation online.
The browser toolbar API is part of the background process API. This part deals with the browser toolbar context, which allows the creation and manipulation of buttons, badges, and popup windows.
Below is a simple example that adds a button to the browser toolbar. It will show a popup window when clicked (showing the local file 'popup.html') and update the badge to reflect how many times the button has been clicked.
//
// The background process (e.g. index.html)
//
var properties = {
disabled: false,
title: "My Extension",
icon: "icon.18x18.png",
popup: {
href: 'popup.html',
width: 100,
height: 100
},
badge: {
display: 'block',
backgroundColor: '#5566ff',
color: '#ffffff',
textContent: '0'
}
};
// Create and add the button to the toolbar
var button = opera.contexts.toolbar.createItem(properties);
opera.contexts.toolbar.addItem(button);
// Update the button badge on button click
var i = 1;
button.addEventListener('click', handleClick, false);
function handleClick() {
// If clicked more than five times, show '5+' in the badge
var badgeText = (i > 5) ? '5+' : i;
// Update badge text
button.badge.textContent = badgeText;
// Update the button title
button.title = "You've clicked the button " + i + " time(s)";
i++;
}