我今天早些时候回答你的一个相关问题:
https://stackoverflow.com/a/8740153/96100
而且,这里是一个答案,我在一年前发布到一个非常类似的问题,最近更新的IE 9的工作:
https://stackoverflow.com/a/4770592/96100
最后,这里是您的可编辑iframe的第二个链接答案的函数版本。它允许你指定一个文件对象:
function insertHtmlAtSelectionEnd(html, isBefore, doc) {
doc = doc || document;
var win = doc.defaultView || doc.parentWindow;
var sel, range, node;
if (win.getSelection) {
sel = win.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.collapse(isBefore);
// Range.createContextualFragment() would be useful here but was
// until recently non-standard and not supported in all browsers
// (IE9, for one)
var el = doc.createElement("div");
el.innerHTML = html;
var frag = doc.createDocumentFragment(), node, lastNode;
while ((node = el.firstChild)) {
lastNode = frag.appendChild(node);
}
range.insertNode(frag);
}
} else if ((sel = doc.selection) && sel.type != "Control") {
range = sel.createRange();
range.collapse(isBefore);
range.pasteHTML(html);
}
}