0

我用 .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", []);

chrome://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);

我的问题

我究竟做错了什么?为什么窗口没有消失?

4

1 回答 1

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
于 2013-03-16T21:25:41.363 回答