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.
Registers a listener for an event specific to the popup window. The listener needs to use the standard EventListener
interface - a function with an Event
object as its first argument (e.g., var myListener = function(event){alert(event.type)}
.
type
: The type of event to listen to.listener
: The function that will be calleduseCapture
: If true, the event listener is only added for the capture phase and targetvoid addEventListener (<DOMString> type, <EventListener> listener, UseCapture)
Listen for an incoming message from the background process. The source event is a messagePort
to the connecting environment.
//
// The background process (e.g. '/background.js').
//
// Set options for the button
var UIItemProperties = {
disabled: false,
title: 'Opera Extension',
icon: 'images/icon_18.png',
popup: {
href: 'popup.html',
width: 500,
height: 400
},
onclick: function() {
opera.extension.broadcastMessage();
}
};
// Create the button and add it to the toolbar
var button = opera.contexts.toolbar.createItem(UIItemProperties);
opera.contexts.toolbar.addItem(button);
//
// The popup script (e.g. '/popup.js').
//
// Note the "on" is removed from "onmessage" here
opera.extension.addEventListener('message', function(event) {
document.write('Message received: ' + event.data);
}, false);
Note that this event listener can also be written using onmessage
, as below.
// Create the button and add it to the toolbar
var button = opera.contexts.toolbar.createItem(UIItemProperties);
opera.contexts.toolbar.addItem(button);
//
// The popup script (e.g. '/popup.js').
//
opera.extension.onmessage = function(event) {
document.write('Message received: ' + event.data);
};