如何用浏览器监听窗口的焦点事件?
通过运行此示例:
<?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>
..您可以看到,仅当焦点不在上时才会引发窗口
的焦点事件。代码>浏览器。我在底部添加了一个按钮,这样您就可以从浏览器中删除焦点,看看我的意思:
- 如果
button
获得焦点并且您最小化并恢复窗口,您将看到 focus 事件发生。 - 如果
浏览器
获得焦点并且您最小化并恢复窗口,则焦点事件将不会发生。
我需要在浏览器获得焦点时发生此焦点事件,知道如何实现此目标吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试改用激活事件。
Try using the activate event instead.