如何检查 Xul 中给定的窗口是否打开?
如何检查 Xul 中给定的窗口是否打开?
我想检查我的桌面应用程序中是否已打开窗口。所以如果是的话我就不会再打开它了。
--我的尝试
我试图使用窗口标题来完成此操作,因此我从 windowManager
获取窗口列表并检查标题,但是 getAttribute
不是来自我可以查询的接口,它来自 element,什么我应该使用接口吗?
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getXULWindowEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface(Components.interfaces[" WHICH INTERFACE TO PUT HERE? "]);
write("WINDOW TITLE = " + win.getAttribute("title"));
}
How to check if a given window is open in Xul?
I would like to check if a window is already openned in my desktop app. So if it is, I'll not open it again.
-- my attempt
I'm trying to accomplish this using the window title, so I get the list of windows from windowManager
and check the title, but the getAttribute
is not from an interface that I can query, it's from element, what interface should I use?
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getXULWindowEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface(Components.interfaces[" WHICH INTERFACE TO PUT HERE? "]);
write("WINDOW TITLE = " + win.getAttribute("title"));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 getXULWindowEnumerator 您应该使用 Components.interfaces.nsIXULWindow
如果您自己打开窗口,您可能可以使用 nsIDOMWindow 属性名称,因为您在 open 函数中设置了窗口的名称。这对用户来说是不可见的,因此您有更多的灵活性。
如果您将窗口名称留空,它每次都会打开一个新窗口。但是,如果您使用窗口名称(除 "" 之外的其他名称),如果窗口不存在,它将创建它,或者使用您指定的名称在已存在的窗口中加载新内容。
这看起来几乎就是你想要的。但是如果有必要,您可以使用 name 属性来避免重新加载。
if you are using getXULWindowEnumerator you should use Components.interfaces.nsIXULWindow
you probably could use the nsIDOMWindow attribute name if you open the windows your self because you set the name of the window in the open function. This is not visible to the user so you have a little more flexibility
If you are leaving the window name blank it will open a new window every time. If you however use a window name (something else than "" ) it will create it if it does not exists, or load the new content in the already existing window with the name you have specified.
Which seems like almost what you want. Butt you could use name attribute to avoid the reload if you have to.
如果您在文档的
元素上设置windowtype="myWindowType"
属性,则只需使用windowMediator.getMostRecentWindow('myWindowType');< /code> 查看您是否已经打开了一个。
If you set a
windowtype="myWindowType"
attribute on your document's<window>
element then you can just usewindowMediator.getMostRecentWindow('myWindowType');
to see whether you already have one open.