opera.extension.postMessage()
Description:
This method is used to post a message to the BackgroundProcess
of the extension.
Parameters:
data
: Data to be posted.ports
: An array of ports to be passed along to theBackgroundProcess
(optional).
Syntax:
void postMessage (<object> data, <array> ports)
Example:
//
// 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);
void postMessage (
This article is licensed under a Creative Commons Attribution 3.0 Unported license.
Comments