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

走远了吗. 提交于 2019-12-12 01:19:17

问题


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?


回答1:


Try using the activate event instead.



来源:https://stackoverflow.com/questions/4763147/how-to-listen-to-focus-event-of-a-window-with-a-browser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!