2013-04-26 46 views
1

我正在創建一個Firefox工具欄上的按鈕,該按鈕將顯示在我將設置的自定義內容下方。將值傳遞給xul面板中的iframe

我使用的是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發生什麼呢?

回答

2

你真的不能「送」的值到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; 

參考:window.frameElement

+0

感謝。這就是訣竅。:) – 2013-04-26 15:25:00