2011-01-21 92 views
0

通过运行这个样本:如何使用浏览器收听窗口焦点事件?

<?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的焦点事件将被抛出只有焦点browser。我加入了底部的按钮,这样你就可以从浏览器中删除的重点和明白我的意思:

  • 如果button的重点是,你最小化和恢复窗口,你会看到焦点事件发生。
  • 如果browser重点并且您最小化和还原窗口,焦点事件将发生而不是发生。

我需要这个焦点事件发生在browser有焦点,任何想法如何实现这个目标?

回答

1

请尝试使用activate事件。

+0

太棒了!谢谢!不知道我是否应该将它发布到bugzilla。 – 2011-01-26 11:24:20