2011-11-04 132 views
0


我有一個像頂級窗口焦點/模糊事件

<frameset rows="100, 200"> 
    <FRAME name="listener" src="frame1.html"> 
    <FRAME name="content" src="http://www.someexternalurl.com/"> 
</frameset> 

在聽者形式的簡單框架試圖聽上面的窗口焦點/模糊:

<body> 

<div id="szamlalo">30</div> 

</body> 
<script type="text/javascript"> 
var inFocus = true; 
var counter = 30; 
var timer; 
$(document).ready(function(){ 
    $(window.top).focus(function(){ 
    //$(window.top).focusin(function(){ 
     inFocus = true; 
    }); 
    $(window.top).blur(function(){ 
    //$(window.top).focusout(function(){ 
     inFocus = false; 
    }); 
    timer = window.setInterval("countdown()",1000); 
}); 
function countdown() 
{ 
    if (counter > 0) 
    { 
     if (inFocus) 
      counter--; 
    } 
    else 
    { 
     window.clearInterval(timer); 
     window.location.href='masik_oldal.html'; 
    } 
    $('#szamlalo').html(counter); 
} 
</script> 

但aparently的主要的瀏覽器都以不同的方式處理,歌劇是它按預期工作的唯一一個。在IE瀏覽器中根本沒有收到模糊,chrome和firefox只收到一次...這是簡單的不同的js引擎實現,還是jQuery中的某些東西?或者我在某個地方犯了一個錯誤?
感謝您的任何想法

+0

爲什麼使用框架?他們是單獨的文件,所以這可能會很棘手。您可能可以使用一個文檔實現相同。 –

回答

0

事件不會冒泡框架集樹。您需要爲每個窗口(框架)安裝單獨的處理程序