【发布时间】:2010-12-02 13:03:39
【问题描述】:
我在 google 代码中找到了this file 的功能:
function SetAlwaysOnTop() {
var chkTop = document.getElementById("itmAlwaysOnTop");
var xulWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem)
.treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow);
if(chkTop.getAttribute("checked") == "true") {
xulWin.zLevel = xulWin.raisedZ;
} else {
xulWin.zLevel = xulWin.normalZ;
}
}
我需要的只是:
var xulWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem)
.treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow);
xulWin.zLevel = xulWin.raisedZ;
但我没有找到 Ci 的定义在哪里。知道会是什么吗?或者任何其他关于如何将窗口始终设置在顶部的想法? (“仅适用于 Windows”的解决方案不适合我)。
--更新
我正在阅读nsIWindowMediator,它有一些方法来处理窗口 Z 顺序。但它说这些方法应该从 c++ 中使用,而不是 javascript。那意味着代码应该从XPCOM组件中使用(我应该作为XPCOM组件来打开窗口)?有没有用过的可以确认一下?
反正我还在看书。
--更新
我已经尝试过 nsIWindowMediator(带有 XPCOM 组件),但是当我设置 Z 级别时它什么也没做。
仍在寻找将窗户放在顶部的方法..
--尝试使用“alwaysraised”:
test.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300"
onload="open('top.xul','GreenfoxChannelWindow','chrome, alwaysraised');"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="MAIN WINDOW"/>
</window>
top.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="ON TOP"/>
</window>
没用。
--尝试使用“zlevel”:
test.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300"
onload="open('top.xul','GreenfoxChannelWindow','chrome');"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="MAIN WINDOW"/>
</window>
top.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300" zlevel="6"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="ON TOP"/>
</window>
没用。使用 alwaysraised 设置,或者在 test.xul 中添加更高或更低的 zlevel(使用 top.xul zlevel="6")
【问题讨论】:
标签: javascript xul xpcom always-on-top