« Documentation Home

opera.extension.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. For opera.extension, this inlcudes 'connect', 'message', and 'disconnect'.

Parameters:

Syntax:

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

Example:

//
// The background process ('/background.js'). 
//

// Listen for a new environment being created (like the popup window) 
opera.extension.addEventListener('connect', function(event) {
  var connected = true;
}, false);

// Listen for messages being sent
opera.extension.addEventListener('message', function(event) {
  var message = event.data;
}, false);

// Listen for environments being destroyed (and communication disabled)
opera.extension.addEventListener('disconnect', function(event) {
  var connected = false;
}, false);