简体   繁体   中英

Passing values to iframe inside xul panel

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?

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 - eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM