我今天早些時候回答你的一個相關問題:
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);
}
}