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 (About this article
| Published in | Dev.Opera |
|---|---|
| Date | December 6, 2011 |
| Author | Opera Software |
| Tags | extensions API, popup |
| Original | Internet Archive |