我已经创建了一个可编辑的iFrame:
<iframe frameborder="0" id="editor"></iframe>
<script type="text/JavaScript">
document.getElementById('editor').contentWindow.document.designMode="on";
document.getElementById('editor').contentWindow.document.close();
$("#editor").contents().find("body").blur(function(){ // Blur functions });
$("#editor").contents().find("body").focus(function(){// focus functions });
</script>
焦点和模糊事件在chrome中被触发,但在firefox中不起作用
解析为:
<iframe frameborder="0" id="editor"></iframe>
<script type="text/JavaScript">
document.getElementById('editor').contentWindow.document.designMode="on";
document.getElementById('editor').contentWindow.document.close();
if(navigator.userAgent.indexOf("Firefox") != -1){
$("#editor").contents().bind('blur', function(){ // Blur functions });
$("#editor").contents().bind('focus', function(){ // focus functions });
}else{
$("#editor").contents().find("body").blur(function(){ // Blur functions });
$("#editor").contents().find("body").focus(function(){ // focus functions });
}
</script>
对于firefox,它可以在content()上设置focus/blur,而不是body。