opera.extension.addEventListener()
Description:
This method is used to listen for events being dispatched. For opera.extension, this inlcudes 'connect', 'message', and 'disconnect'.
Parameters:
type: Type of event; allowed values are:"message","disconnect", and"connect".eventListener: The function to be executed when the event occurs.useCapture: Boolean, keep false for now; note: this value currently has no purpose.
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);
This article is licensed under a Creative Commons Attribution 3.0 Unported license.
Comments
No new comments accepted.