2012-12-01 17 views
0

在我的Firefox插件中,我有一個非模態窗口,在用戶瀏覽時保持打開狀態。該插件也有一個工具欄。當在工具欄上按下按鈕時,會調用一個函數來設置窗口中某些屬性的值。如何在設置屬性後更新對話窗口?

現在,在我的代碼中,我可以調用該函數,但窗口永遠不會改變。

但是,我使用onload偵聽器調用相同的函數,並且在那裏工作正常。我在函數中放入了一個alert,它確實被調用,但是這些改變從不顯示在窗口中。

如何確保在我的窗口上顯示更改?這裏是我的一些示例代碼:

var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); 
    var mywindow = windowManager.getMostRecentWindow('mywindow'); 
    if (mywindow) { 
     alert("found it!"); 
     var thislabel = document.getElementById("mylabel"); 
     thislabel.setAttribute("label", "New Text"); 
    } else { 
     alert("The window is not open."); 
    } 
} 

回答

1

我有點猜測在這裏,但也許你需要訪問正確的文件?

var thislabel = mywindow.document.getElementById("mylabel"); 

// alert something if the element was found 
thislabel !== null && alert('found'); 
+0

就是這樣!該函數被調用,但它缺少窗口句柄。謝謝! – bgmCoder

+0

嗯..這是行得通的,我很高興標出了答案,但它似乎並沒有更新窗口,即使該函數被調用。任何線索? – bgmCoder

相關問題