如何使用浏览器收听窗口的焦点事件? [英] How to listen to focus event of a window with a browser?
本文介绍了如何使用浏览器收听窗口的焦点事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过运行此示例:
<?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>
..你可以看到 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:
- 如果
button
获得焦点并且您最小化并恢复窗口,您将看到焦点事件发生. - 如果
browser
获得焦点并且您最小化并恢复窗口,则焦点事件将不发生.
- 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.
我需要在 browser
获得焦点时发生此焦点事件,知道如何实现此目标吗?
I need this focus event to happen when the browser
has the focus, any idea how to accomplish this goal?
推荐答案
尝试改用 activate 事件.
Try using the activate event instead.
这篇关于如何使用浏览器收听窗口的焦点事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文