简体   繁体   中英

How to listen to focus event of a window with a browser?

By running this sample:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="640" height="480"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    onload="">

    <script>
        <![CDATA[
            function onfocus() {
                dump("FOCUSED!\n");
            }
            window.addEventListener("focus", onfocus, false);
        ]]>
    </script>

    <browser id="gmail" type="content" src="http://gmail.com/" flex="1" />
    <button label="click here to remove the focus from the browser"/>

</window>

..you can see that the window 's focus event will be thrown only if the focus is not on the browser . I added a button in the bottom, so you can remove the focus from the browser and see what I mean:

  • If the button is focused and you minimize and restore the window, you'll see the focus event occur.
  • If the browser is focused and you minimize and restore the window, the focus event will not occur.

I need this focus event to happen when the browser has the focus, any idea how to accomplish this goal?

尝试改用Activate事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM