opera.extension.bgProcess
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:
A reference to the window
object of the background process. The bgProcess
object can be used to set and get variables and functions between the background script and a popup window or preferences page. Note that it cannot be used in injected scripts for security reasons.
Example (variable):
The value of a variable in the background process is displayed when the preferences page is opened.
//
// The background process ('/background.js').
//
var data = 'This is some important data in the backround process';
//
// An extension environment (e.g. '/options.js')
//
window.addEventListener('DOMContentLoaded', function() {
var myElement = document.createElement('p');
myElement.textContent = opera.extension.bgProcess.data;
document.body.appendChild(myElement);
}, false);
Example (function):
Executing a function in the background process from the preferences page.
//
// The background process ('/background.js').
//
function doReverse(text) {
var output = '';
for (var i = text.length - 1; i >= 0; i--) {
output += text.charAt(i);
}
return output;
}
//
// An extension environment (e.g. '/options.js')
//
window.addEventListener('DOMContentLoaded', function() {
var reversedText = opera.extension.bgProcess.doReverse('enihcam ym no skrow tI');
}, false);
This article is licensed under a Creative Commons Attribution 3.0 Unported license.
Comments