我在谷歌代码中找到了这个文件的功能:
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 级别时它什么也没做。
仍在寻找一种将窗户放在顶部的方法..
--尝试“总是提出”:
测试.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>
顶部.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”:
测试.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>
顶部.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")