Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 关注加载时iframe中的内容可编辑体_Javascript_Iframe_Contenteditable - Fatal编程技术网

Javascript 关注加载时iframe中的内容可编辑体

Javascript 关注加载时iframe中的内容可编辑体,javascript,iframe,contenteditable,Javascript,Iframe,Contenteditable,这在Firefox和IE中运行良好,但在Chrome中无法运行: self.editorIframeDocument.body.focus() editorIframeDocument==contentDocument| |contentWindow.document取决于浏览器 .body.focus()使编辑器加载时,我可以立即开始键入。完美,然而,在铬合金中它不起作用。我尝试连接到iframe以及iframe#文档,但没有成功 我看到了一些设置选择并删除它的黑客行为,但它们都是

这在Firefox和IE中运行良好,但在Chrome中无法运行:

self.editorIframeDocument.body.focus()
editorIframeDocument
==
contentDocument
| |
contentWindow.document
取决于浏览器

.body.focus()
使编辑器加载时,我可以立即开始键入。完美,然而,在铬合金中它不起作用。我尝试连接到iframe以及iframe
#文档
,但没有成功

我看到了一些设置选择并删除它的黑客行为,但它们都是
中的示例,其中包含特定的HTML,而不是
中可能包含从零到大量文本的任何内容


没有jQuery。

问题是编辑器还没有加载,所以Chrome不让我关注它。检查就绪状态修复了该问题:

if (self.settings.focusOnLoad) {
  // We need to wait until all three iframes are done loading by waiting until the parent
  // iframe's ready state == complete, then we can focus on the contenteditable
  self.iframe.addEventListener('readystatechange', function () {
    if (self.iframe.readyState == 'complete') {
      self.editorIframeDocument.body.focus();
    }
  });
}

你以前什么时候打电话给福克斯的?我想我之前已经用计时器或其他东西解决了这个问题。我是在readystatechange侦听器之外调用它的。因此,它会检查是否设置了该选项并运行焦点代码,但由于该元素在Chrome中尚不存在,因此无法聚焦。