2

如何在 xul 中制作对接面板。它应该像在萤火虫中一样工作。我试过这样的事情:

myWindow = window.open("chrome://project/content/myWindow.xul", "someRandomName", "chrome");

myWindow.xul 是:

<?xml version="1.0" encoding="utd-8"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<?xul-overlay href="chrome://project/content/myPanel.xul"?>

    <window id="dockedPanel" title="my super extension" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
        <hbox flex="1">
            <vbox id="myPanel"/>
        </hbox>
    </window>

myPanel.xul 是我的面板,myPanel 是 myPanel.xul 中 vbox 的 id

当我像这样打开窗口时,它看起来很像我想要的,但是所有按钮/其他组件都不起作用。例如,如果我在 myPanel.xul 中有按钮:

<button id="myButton" label="button" onclick = "jsScriptFromOtherFile.someFunction()"/>

如果我单击 myWindow 上的该按钮,则不会调用 someFunction。我不知道为什么,以及如何使它工作。

4

1 回答 1

0

我想您的问题是您希望所有窗口都共享 JavaScript 代码/状态/范围,无论您如何称呼它;在“myWindow.xul”或“myPanel.xul”中加载的任何脚本中都没有定义“jsScriptFromOtherFile”,它是在调用window.open.

每个“窗口”(或选项卡、iframe 等)都有自己的全局对象。要从不同的“窗口”访问变量,您首先必须获得该窗口的句柄。请参阅在 chrome 代码中使用窗口

于 2011-07-17T00:01:25.600 回答