在我的火狐插件中,我有一个小的非模态窗口,当用户浏览时保持打开状态。 该插件还有一个工具栏。 按下工具栏上的按钮时,将调用一个函数来设置窗口中某些属性的值。
现在,在我的代码中,我可以很好地调用该函数,但窗口永远不会更改。
但是,我使用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.");
}
}
我在这里有点猜测,但也许您需要访问正确的文档?
var thislabel = mywindow.document.getElementById("mylabel");
// alert something if the element was found
thislabel !== null && alert('found');