Student
Student

Reputation: 28345

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:

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

Upvotes: 0

Views: 1240

Answers (1)

Neil
Neil

Reputation: 55402

Try using the activate event instead.

Upvotes: 1

Related Questions