我正在创建一个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>
有没有类似的方法将“config”变量发送到xul文件,就像openDialog一样?
答案 0 :(得分:1)
您无法真正向iframe
“发送”某个值,但您可以将其保留在iframe
内运行的代码可以找到它的位置 - 例如在iframe
标记的expando属性中:
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;