2013-08-04 28 views
0

我在更改焦點時更改iframe內容。它適用於FF,但focusblur事件不會在Google Chrome中觸發!Chrome瀏覽器不會觸發內容中文檔的焦點和模糊事件可編輯iframe

var iframe = $('#iframe').get(0); 
iframe.onload = function(){ 

    iframeDoc = $(iframe.contentWindow.document); 
    iframeDoc.focus(function(){ 
     alert('focused'); 
    }).blur(function(){alert('blur'); 
     alert('blured'); 
    }); 

} 

然而,其他事件一樣keyupkeypress正在工作。你知道有什麼問題以及如何處理?

+1

託管在同一個域中的iframe的內容? –

+0

@StevenV是的,它託管在相同的域名 – Omid

回答

4

在Chrome瀏覽器內嵌框架文件不具有焦點或模糊的情況下,窗口的作用:

var iframe = document.getElementById('iframe'); 
var iWindow = iframe.contentWindow; 

iWindow.onfocus = function(){ 
    console.log('focused'); 
} 
iWindow.onblur = function(){ 
    console.log('blured'); 
} 

FIDDLE

+0

是的,我正在這樣做 – Omid

0

根據http://api.jquery.com/focus/focus只能用於某些元素(主要是表單元素)。您可能需要考慮在body標籤上的iframe中捕獲點擊事件,以確定用戶是否與其交互。

相關問題