How to pass out ContentScript data out to a module-global variable in JavaScript?
I been working on a firefox extension project and now I'm stuck on this,
var abc = 123;
var pageMod = require("page-mod");
pageMod.PageMod({
in开发者_如何学编程clude: "*",
contentScriptWhen: 'ready',
contentScript: 'var newabc = 456;',
});
where abc is a global variable and newabc is a variable within the contentScript.
How do I make abc = newabc ?
Thanks!!
For the Addon-SDK v1.0b3's PageMod API:
var abc = 123;
var pageMod = require("page-mod");
pageMod.PageMod({
include: "*",
contentScriptWhen: 'ready',
contentScript: 'var newabc = 456;postMessage(newabc);',
onAttach: function onAttach(worker) {
worker.on('message', function(newabc) {
abc = newabc;
});
}
});
精彩评论