对appShellService.unregisterTopLevelWindow(topXulWindow)没有影响; (隐藏窗口)

时间:2013-03-16 11:10:20

标签: firefox-addon xul xpcom

我使用.xul覆盖chrome://browser/content/browser.xul,在主菜单中添加一个按钮。点击它会打开另一个带有.xul窗口的ChromeWindow。

var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
var bgwin = ww.openWindow(null, 'chrome://myextension/content/myBrowser.xul', 'MyName', "chrome, resizable=yes, width=1024, height=600, minimizable, maximizable", []);

铬://myextension/content/myBrowser.xul:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="myextension-my-browser"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    title="mybrowser"
    windowtype="mybrowser"
    >
    <script type="application/x-javascript" src="chrome://myextension/content/myBrowser.js" />
    <browser id="browser" type="content" flex="1" src="about:blank" />
</window>

工作正常。但是,我想要隐藏那个窗口。做(完全不可见)(在myBrowser.js中)。但没有任何反应:

var topXulWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
            .getInterface(Components.interfaces.nsIWebNavigation)
            .QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
            .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
            .getInterface(Components.interfaces.nsIXULWindow);
var appShellService = Components.classes["@mozilla.org/appshell/appShellService;1"].getService(Components.interfaces.nsIAppShellService);               
appShellService.unregisterTopLevelWindow(topXulWindow);

我的问题

我做错了什么?为什么窗户不会消失?

1 个答案:

答案 0 :(得分:0)

使用以下代码段

添加代码
var basewindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  .getInterface(Components.interfaces.nsIWebNavigation)
  .QueryInterface(Components.interfaces.nsIDocShell)
  .QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
  .QueryInterface(Components.interfaces.nsIBaseWindow);

basewindow.visibility = false;
basewindow.enabled = false;

// now unregister