Xul 的 window.blur() 不起作用?还有其他选择吗?
我正在尝试使用 window.blur() 打开一个没有焦点的窗口它(或者聚焦和散焦非常快,所以看起来它没有聚焦)。
但貌似不行,有其他办法吗?
我的尝试:
blurTest.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">
<script>
<![CDATA[
function onkeypress(event) {
// for this sample don't matter which key is pressed
open('second.xul','SecondWindow','chrome, width=400, height=300');
}
addEventListener("keypress", onkeypress, false);
]]>
</script>
<label value="MAIN WINDOW"/>
</window>
secondary.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300"
onload="blur();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="SECOND" />
</window>
Obs. 我们可以考虑使用 setTimeout(window.focus, 1) 在打开后将焦点回调回我的窗口第二个窗口。但我需要第二个窗口来处理焦点。完美的情况是,如果第二个窗口永远无法获得焦点,只需打开/恢复窗口而不获得焦点。
I'm trying to use window.blur() to open a window without focus it (or focus and unfocus really fast, so looks like it was not focused).
But it looks like it doesn't work, is there an alternative?
My attempt:
blurTest.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">
<script>
<![CDATA[
function onkeypress(event) {
// for this sample don't matter which key is pressed
open('second.xul','SecondWindow','chrome, width=400, height=300');
}
addEventListener("keypress", onkeypress, false);
]]>
</script>
<label value="MAIN WINDOW"/>
</window>
second.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300"
onload="blur();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="SECOND" />
</window>
Obs. We can think about use setTimeout(window.focus, 1) to call the focus back the my window after open the second window. But I need the second window to handle the focus. The perfect scenario would be if the second window was never able to get the focus, just open/restore the window without get focus.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
openDialog
调用中的popup
窗口功能打开 XUL 窗口,就好像它是弹出窗口一样。这应该会打开一个不会窃取焦点的最顶层窗口。请注意,默认情况下,弹出窗口没有操作系统镶边;在 Windows 上,您可以添加titlebar
功能(它为您提供一个类似于调色板窗口的迷你标题栏)和close
按钮(与标题栏结合使用),但是我不知道哪些功能标志可以在其他平台上使用。桌面警报在 Windows 上仍然使用此功能,但我相信在 Linux 上他们现在使用 libnotify,在 Mac 上他们使用 Growl。
You can open a XUL window as if it was a popup by using the
popup
window feature in theopenDialog
call. This should open a topmost window that doesn't steal focus. Note that by default a popup window has no OS chrome; on Windows you can add thetitlebar
feature (which gives you a mini title bar as for a palette window) and theclose
button (in conjunction with the title bar), but I don't know which feature flags work on other platforms.Desktop alerts still use this feature on Windows but I believe on Linux they now use libnotify and on the Mac they use Growl.