Button.addEventListener()

By Opera Software

Description:

This method is used to listen for events being dispatched.

Parameters:

  • type: Type of event; allowed values are: click and remove.
  • eventListener: The function that is executed when the event occurs.
  • useCapture: Boolean, and should be kept as false for now. Note: this value currently has no purpose.

Syntax:

void addEventListener(<DOMString> type, eventListener, <boolean> useCapture)

Example:

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

// Set the button's properties
var properties = {
  disabled: false,
  title: "My Test Extension",
  icon: "icon.18x18.png"
};	

// Add the button to the browser UI
var button = opera.contexts.toolbar.createItem(properties);
opera.contexts.toolbar.addItem(button);

// Update the button title each time the button is clicked
var i = 1; 
button.addEventListener('click', handleClick, false);

function handleClick() {
  button.title = "You've clicked the button " + i + " time(s)"; 
  i++;
}

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

Comments

No new comments accepted.