问题描述
我创建了一个firefox扩展,在工具栏上有一个按钮,它会显示下面的自定义内容。
我使用XUL文件创建这个内容的结构,我是这样打开:
var config = {confirm:false,
用户名:,
密码:};
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事件);
level =top>
< hbox id =myext-panel-containeralign =top>
< iframe id =myext-toolbar-menuflex =1/>
< / hbox>
< / panel>
< / toolbarbutton>
< / toolbarpalette>
是否有类似的方式将config变量发送到xul文件, openDialog?
你不能真正的发送一个值到 iframe ,但是你可以把它放在 iframe 内运行的代码可以找到的地方 - 例如在 iframe 标记的expando属性中:
frame._myExtConfig = config;
frame.src =chrome://myext/content/login.xul;
运行在 chrome://myext/content/login.xul 可以执行以下操作:
$ b
var config = window.frameElement ._myExtConfig;
供参考:
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 - 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
这篇关于将值传递给xul面板中的iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!