Chrome不会触发内容可编辑iframe中的文档焦点和模糊事件
问题描述:
我正在改变iframe内容。它适用于FF,但焦点
和模糊
事件不会在Google Chrome中触发!
I'm changing the iframe content while it is focused. It works in FF but focus
and blur
event does not trigger in Google Chrome !
var iframe = $('#iframe').get(0);
iframe.onload = function(){
iframeDoc = $(iframe.contentWindow.document);
iframeDoc.focus(function(){
alert('focused');
}).blur(function(){alert('blur');
alert('blured');
});
}
尽管如此,其他事件如 keyup
, keypress
正在运作。你知道问题是什么以及如何处理吗?
Nevertheless, Other event like keyup
, keypress
are working. Do you know what's the problem and how to handle it?
答
在Chrome中,iFrame文档没有焦点或模糊事件,窗口确实:
In Chrome the iFrame document doesn't have a focus or blur event, the window does :
var iframe = document.getElementById('iframe');
var iWindow = iframe.contentWindow;
iWindow.onfocus = function(){
console.log('focused');
}
iWindow.onblur = function(){
console.log('blured');
}