Xul 的 window.blur() 不起作用?还有其他选择吗?

发布于 2024-10-16 11:53:43 字数 1340 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酒忠诚 2024-10-23 11:53:43

您可以使用 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 the openDialog 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 the titlebar feature (which gives you a mini title bar as for a palette window) and the close 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文