【发布时间】:2012-05-21 01:03:50
【问题描述】:
我正在构建一个 CMS 应用程序,我现在正在为 IE 调试它。但是发生了一些我无法理解的事情。
首先我有一个包含页面内容的 div。我提取 div 的内容并使用 javascript 创建一个 iFrame 并将其附加到 div。这是为了制作所见即所得的编辑器。然后,当我想将内容添加到 iFrame 时,问题就开始了。由于某种原因,IE 无法访问 iFrame 的正文。我可以提醒 iFrame 的文档,它给了我 [object Document] 或 [object HTMLDocument],但是当我提醒正文时,我得到了 null。
我使用这个函数来获取文档作为 javascript 对象的一部分:
iframedoc: function(aID) {
if (document.getElementById(aID).contentDocument){
return document.getElementById(aID).contentDocument;
} else {
var iFrame = document.getElementById(aID);
return iFrame.contentWindow.document;
}
},
这是我第一次这么称呼它:
tas[i].innerHTML = "";
tas[i].appendChild(ta_edit_functions);
tas[i].appendChild(ta_edit);
tas[i].appendChild(ta_result);
alert(ta.iframedoc(ta_edit_id));
ta.iframedoc(ta_edit_id).body.innerHTML = ta_edit_content;
ta.iframedoc(ta_edit_id).designMode = 'on';
这里我清空 div,添加一个包含所见即所得函数的 div、iFrame 和 textarea 以最终提交表单。
我正在 IE 8 和 9 中进行测试。最奇怪的是,当我在 IE 8 中第一次调用 iframedoc 之前发出警报时,我突然得到了正文。
如果有人至少能指出我正确的方向,我将不胜感激。我真的不知道发生了什么。
【问题讨论】:
标签: javascript internet-explorer iframe