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.
This method is used to post a message to the BackgroundProcess
of the extension.
data
: Data to be posted.ports
: An array of ports to be passed along to the BackgroundProcess
(optional).void postMessage (<object> data, <array> ports)
//
// 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
},
badge: {}
};
// Create the button and add it to the toolbar
var button = opera.contexts.toolbar.createItem(UIItemProperties);
opera.contexts.toolbar.addItem(button);
// Check for incoming messages
opera.extension.onmessage = function(event) {
button.badge.textContent = event.data;
};
//
// The popup script (e.g. '/popup.js').
//
// Set an integer and send it to the background process
var num = 42;
opera.extension.postMessage(num);
document.write('Message sent: ' + num);