Button.icon

By Opera Software

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

This property represents the icon for the Button. It can reference the relative path to a data URI, an image located inside the package, or it can point to an external URL.

Example:

The below example changes the button icon on each click.

//
// The background process (e.g. index.html)
//

// Create a button and add it to the browser UI
var properties = {
  title: "My Extension",
  icon: "icon.18x18.png",
};
var button = opera.contexts.toolbar.createItem(properties);
opera.contexts.toolbar.addItem(button);

// Track how many times the button has been clicked
var i = 1;

// Handle button clicks
button.addEventListener('click', handleClick, false);

// Change the icon to 'icon2' every time the click count is an even number
function handleClick() {
  if (i % 2 == 1) {
    button.icon = "icon2.18x18.png";
  } else {
    button.icon = "icon.18x18.png";
  }

  // Increase the click count
  i++;
}

This article is licensed under a Creative Commons Attribution 3.0 Unported license.

Comments

No new comments accepted.