Passing values to iframe inside xul panel

末鹿安然 提交于 2019-12-25 08:58:15

问题


I am creating a firefox extension that has a button on the toolbar that will show below custom content that i will set.

I was using a XUL file to create the structure of this content, and i was opening it like this:

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);

Now i'm taking another approach, by using an iframe inside a panel to dynamically use one of multiple xul files as src. Here's the 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>

Is there a similar way of sending that "config" variable to the xul file, as it happens with openDialog?


回答1:


You cannot really "send" a value to an iframe but you can leave it in a place where the code running inside the iframe can find it - e.g. in an expando property of that iframe tag:

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

The code running in chrome://myext/content/login.xul can do the following then:

var config = window.frameElement._myExtConfig;

For reference: window.frameElement



来源:https://stackoverflow.com/questions/16236010/passing-values-to-iframe-inside-xul-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!