3

我在谷歌代码中找到了这个文件的功能:

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")

4

2 回答 2

2

发现:只要用openDialog打开它,它就会一直在最前面。

前任:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300"
    onload="openDialog('top.xul','TopWindow','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"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="ON TOP" />

</window>
于 2011-02-08T13:57:08.973 回答
1

如果您总是希望窗口位于顶部,那么最简单的方法是alwaysraised在打开窗口时使用 chrome 标志。

如果您不能自己打开窗口,第二个最简单的方法是<window zlevel="6">在您的 XUL 中使用。你甚至可以持久化 zlevel;SeaMonkey 的帮助窗口会执行此操作,使用上下文菜单选项来切换 zLevel。

顺便说一下,Ci是一个常见的缩写,因为在 80 个字符的行上很难Components.interfaces写(例如) 。Components.interfaces.nsIXULWindow.rasiedZ

于 2011-01-22T14:20:15.397 回答