« Documentation Home

Button.addEventListener()

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.

Description:

This method is used to listen for events being dispatched.

Parameters:

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