opera.extension.onconnect
From Opera 15 onward, Opera 11 & 12’s extension format is no longer supported, and instead, we’ve switched to Chromium’s extension model. Check out our new documentation for developing extensions for Opera 15 and higher and start building your own extensions.
Description:
This event listener is invoked when an injected script, popup, or preferences environment is created that enables communication. The event's source (event.source) is a messagePort to the connecting environment. The following function will execute when a preferences page is opened, for example.
Example:
//
// The background process ('/background.js').
//
opera.extension.onconnect = function(event) {
var connected = true;
};
/p
This article is licensed under a Creative Commons Attribution 3.0 Unported license.
Comments
-
To post e.g. the extension's preferences to the injected script you can use:
-
>To post e.g. the extension's preferences to the injected script you can use
No new comments accepted.QuHno
Sunday, April 1, 2012
opera.extension.onconnect = function(event) { event.source.postMessage(JSON.stringify(widget.preferences)); };In the injected script you can parse the messages like this:
var preferences; opera.extension.onmessage = function (event) { preferences = JSON.parse(event.data); }Fr0sT
Wednesday, October 17, 2012
Unnecessary, injected scripts have access to widget.preferences directly.
Would be nice if there would be a description for messagePort type. Is there a way to tell what kind of object launched this event (script/tab/prefs)?