0

I encounter a problem with my firefox addon.I write code in the main.js like this:

var mypanel = require("sdk/panel").Panel({
  width: 322,
  height: 427,
  contentURL: data.url("main.html"),
  include:["http://*/*","https://*/*"],
  contentScriptFile: [data.url("js/content.js")]  
});


mypanel.on('message', function(message) {
    switch(message.type) {
      case 'type1':
        console.log(message.content);
        break;
      case 'type2':
        console.log(message.content);
        break;
     }
});

the code in the content.js:

self.port.emit("message",{type:"type1",content:"content1"});

When I run the code, the Mozilla Addon-Builder remind me that "TypeError: self.port is undefined",so what's wrong with my code?Or the way I write about the Firefox port messaging is wrong? How should I write the code? Thank you.

4

1 回答 1

1

请参阅脚本可信面板内容

于 2013-07-25T14:31:14.220 回答