开发者

Xul's window.blur() doesn't work? Is there an alternative?

开发者 https://www.devze.com 2023-02-09 17:55 出处:网络
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).

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", onke开发者_如何学Goypress, 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号