问题
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