本文介绍了如何将Xul窗口设置为“Always On Top”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现具有以下功能:

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不适合我)。

But I'm not finding what where's the Ci defined. Any idea what can it be? Or any other idea of how to set a window always on top? (that solution "just for windows" don't fits to me).

- 更新

我正在阅读,其中有一些方法可以处理窗口Z顺序。但是它说这些方法应该用于c ++,而不是javascript。这意味着代码应该从XPCOM组件中使用(我应该作为XPCOM组件来打开窗口)?是否有人已经使用它可以确认?

I'm reading about the nsIWindowMediator, which has some methods to handle the window Z order. But it's saying that the methods should be used from c++, not javascript. That means the code should be used from XPCOM components (I should as XPCOM component to open the window)? Does anyone that already used it could confirm?

无论如何我还在阅读。

- -update

我已经尝试过nsIWindowMediator(带有XPCOM组件)但是当我设置Z级别时它什么也没做。

I've tried the nsIWindowMediator (with a XPCOM component) but it just does nothing when I set the Z level.

仍在寻找一种方法将窗户置于最顶层..

Still look for a way to put the window aways on top..

- 尝试使用'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 setted,或者向test.xul添加更高或更低的zlevel(使用top.xul zlevel =6)

didn't worked. Nither with alwaysraised setted, or adding a higher or lower zlevel to the test.xul (with top.xul zlevel="6")

推荐答案

找到:只需使用openDialog打开它,它将始终位于顶部。

Found: just open it using openDialog, and it will be always on top.

Ex:

<?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>

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>

这篇关于如何将Xul窗口设置为“Always On Top”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 08:50