Developers › Dev.Opera

Button.icon

December 6, 2011 · by Opera Software

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++;						
}

About this article

Published inDev.Opera
DateDecember 6, 2011
AuthorOpera Software
TagsButton and Badge, extensions API, Toolbar
OriginalInternet Archive