如何从 Firefox 插件中的面板触发面板?
How to fire a panel from a panel in Firefox addon?
我有这样的结构:
Addon Directory
index.js
Data Directory
-panel1.html
-panel1.js
-panel2.html
-panel2.js
我在index.js
中定义了panel1
和panel2
。我将 panel1
附加到工具栏按钮。 panel1.html
包含一个 link 应该打开 panel2.html
.
问题是:
当我在 panel1.js
中调用 panel2.show()
时,出现此错误:panel2.show is not a function
这是代码:
var geLink= document.getElementById("mylink");
getLink.addEventListener('click', function (event)
{
console.log("link clicked");
panel2.show();
},false);
如何从 panel1 触发 panel2?这可能吗?
我知道无法从主要插件脚本外部调用 show 方法。那么,单击 panel1
中的 link 时显示 panel2.html
并执行其内容脚本的正确方法是什么?是通过使用 window.open()
吗?
如果是这种情况,我如何告诉 panel2
脚本在 panel2.html
window 打开之前不执行?因为当我尝试它时,panel2
脚本在我单击 panel1 中的 link 和 panel2.html
页面打开之前执行。
无法从第一个面板发射第二个面板。不可能同时有两个面板。
Opening a panel will close any panel created by the Panel()
constructor that is already open, even if that panel was opened by a
different Add-on SDK based extension.
但是,您可以启动包含内容脚本的普通 HTML 页面,而不是面板。在索引中创建一个 pageMod 对象:
var pageMod = require('sdk/page-mod').PageMod({
include: "resource://extensionfile/data/page.html",
contentScriptFile:'./myscript.js',
contentScriptWhen: 'ready',
onAttach: function(worker) {
worker.port.emit("going-from-index", myarray);
worker.port.on("coming-from-panel", receivedvalue); }
});//end var pageMod
在面板中,听到 link 单击,然后打开 html 页面:
link = document.getElementById("click-link");
link.addEventListener('click',function (event)
{
window.open('page.html');
}
);
我有这样的结构:
Addon Directory
index.js
Data Directory
-panel1.html
-panel1.js
-panel2.html
-panel2.js
我在index.js
中定义了panel1
和panel2
。我将 panel1
附加到工具栏按钮。 panel1.html
包含一个 link 应该打开 panel2.html
.
问题是:
当我在 panel1.js
中调用 panel2.show()
时,出现此错误:panel2.show is not a function
这是代码:
var geLink= document.getElementById("mylink");
getLink.addEventListener('click', function (event)
{
console.log("link clicked");
panel2.show();
},false);
如何从 panel1 触发 panel2?这可能吗?
我知道无法从主要插件脚本外部调用 show 方法。那么,单击 panel1
中的 link 时显示 panel2.html
并执行其内容脚本的正确方法是什么?是通过使用 window.open()
吗?
如果是这种情况,我如何告诉 panel2
脚本在 panel2.html
window 打开之前不执行?因为当我尝试它时,panel2
脚本在我单击 panel1 中的 link 和 panel2.html
页面打开之前执行。
无法从第一个面板发射第二个面板。不可能同时有两个面板。
Opening a panel will close any panel created by the Panel() constructor that is already open, even if that panel was opened by a different Add-on SDK based extension.
但是,您可以启动包含内容脚本的普通 HTML 页面,而不是面板。在索引中创建一个 pageMod 对象:
var pageMod = require('sdk/page-mod').PageMod({
include: "resource://extensionfile/data/page.html",
contentScriptFile:'./myscript.js',
contentScriptWhen: 'ready',
onAttach: function(worker) {
worker.port.emit("going-from-index", myarray);
worker.port.on("coming-from-panel", receivedvalue); }
});//end var pageMod
在面板中,听到 link 单击,然后打开 html 页面:
link = document.getElementById("click-link");
link.addEventListener('click',function (event)
{
window.open('page.html');
}
);