1

我在 Firefox 插件开发中遇到了麻烦。

【现象】:firefox插件栏面板页面收不到消息,消息是panel.html上的iframe发送的。

这是我的代码:

/ * 在文件 [popup.html] * / // 在正文中我添加了一个 iframe 元素。

   iframe src="http://localhost/hello.html"

/ * 在文件 [popup.js] * // 我添加了一个监听器

   window.addEventListener("message", 
    function(event) {
        console.log("popupJS Receive Event from WebPage(" + event.origin);      
        console.log(event);
        //alert(event);
    });

/ *在远程页面hello.html * //我通过点击发送消息。 强调文本

   window.postMessage({ type: "FROM_PAGE", text: "Hello from the webpage!" }, "http://dicrectpass.com");

=====>> 但是,我仍然无法收到来自 iframe 的消息!为什么?

4

1 回答 1

1

我遇到了同样的问题。然后我意识到我正在加载的 HTML 文档中包含我的 Javascript,而不是通过 Panel 构造函数。一旦我把它关掉,它工作得很好。

面板参考

var pnl = panel.Panel({
    width: 300,
    height: 300,
    contentURL: self.data.url('popup.html'),
    contentScriptFile: [
        self.data.url('jquery.js'),
        self.data.url('popup.js')
    ],
    onMessage: function(message) {
        console.log(message);
    }
});
于 2014-03-23T19:31:01.843 回答