Reputation: 38092
I meet a strange thing with Firefox addon development. Why addon
is undefined ?
-- main.js --
var login = panels.Panel({
contentURL: data.url("login.html"),
contentScriptFile: data.url("login.js")
});
login.port.on('send', function onSend(login, password) {
core.getTokens(login, password);
login.hide();
});
-- login.js --
document.querySelector('#ok').addEventListener('click', function(event) {
addon.port.emit('send', document.querySelector('#login').value, document.querySelector('#password').value);
});
document.querySelector('#cancel').addEventListener('click', function(event) {
addon.port.emit('close');
});
I got this error: login.js: addon is not defined
. So, what's wrong? Thanks.
Upvotes: 1
Views: 186
Reputation: 5054
The addon
object is defined when your script is included through a script
tag by the login.html
file.
Since you use the contentScriptFile
option, you have to use the self
object.
Upvotes: 2