![](/img/trans.png)
[英]XUL: how to allow access to top window from a browser script (when src is localhost)
[英]How to place a Xul window as “Always On Top”?
我在google代码中找到了这个带有以下功能的文件:
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”不适合我)。
--update
我正在阅读nsIWindowMediator ,它有一些处理窗口Z顺序的方法。 但是它说这些方法应该用于c ++,而不是javascript。 这意味着代码应该从XPCOM组件中使用(我应该作为XPCOM组件来打开窗口)? 是否有人已经使用它可以确认?
无论如何我还在读书。
--update
我已经尝试过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 setted,或者在test.xul中添加更高或更低的zlevel(top.xul zlevel =“6”)
找到:只需使用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>
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>
如果您总是希望窗口位于顶部,那么最简单的方法是在打开窗口时使用alwaysraised
chrome标志。
如果你不打算自己打开窗口,第二种最简单的方法是在你的XUL中使用<window zlevel="6">
。 你甚至可以坚持zlevel; SeaMonkey的帮助窗口执行此操作,使用上下文菜单选项切换zLevel。
顺便说一下, Ci
是Components.interfaces
的通用缩写,因为在80个字符的行上编写(例如) Components.interfaces.nsIXULWindow.rasiedZ
是很困难的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.