0

我正在创建一个 Firefox 扩展,它在工具栏上有一个按钮,该按钮将显示在我将设置的自定义内容下方。

我正在使用 XUL 文件来创建此内容的结构,并且像这样打开它:

var config = {  confirm: false ,
                    username:"",
                    password:""};

window.openDialog( "chrome://myext/content/login.xul",
        "",
        "centerscreen=no,all=no,titlebar=no,chrome=yes,
        toolbar=no,dialog=no,resizable=no,modal=yes",
        config);

现在我采用另一种方法,通过在面板内使用 iframe 来动态使用多个 xul 文件中的一个作为 src。这是xul:

<toolbarpalette id="BrowserToolbarPalette">
    <toolbarbutton id="myextToolbarIcon"
                   image='chrome://myext/content/images/myext-mini-logo.png'
                   type="panel"
                   class="toolbarbutton-1 chromeclass-toolbar-additional"
                   tooltiptext="myext">
        <panel id="myext-panel"
               type="arrow"
               noautofocus="true"
               consumeoutsideclicks="true"
               onpopupshowing="startscreen(event);"
               level="top">
            <hbox id="myext-panel-container" align="top">
                <iframe id="myext-toolbar-menu" flex="1"/>
            </hbox>
        </panel>
    </toolbarbutton>
</toolbarpalette>

是否有类似的方式将“配置”变量发送到 xul 文件,就像 openDialog 一样?

4

1 回答 1

1

您不能真正将值“发送”到 an,iframe但您可以将其留在运行在内部的代码可以找到它的地方- 例如在该标签iframe的 expando 属性中:iframe

var frame = document.getElementById("myext-toolbar-menu");
frame._myExtConfig = config;
frame.src = "chrome://myext/content/login.xul";

然后运行的代码chrome://myext/content/login.xul可以执行以下操作:

var config = window.frameElement._myExtConfig;

供参考:window.frameElement

于 2013-04-26T12:52:15.733 回答