In IE <= 10 you can use the pasteHTML
method of the TextRange
representing the selection:
var doc = document.getElementById("your_iframe").contentWindow.document;
if (doc.selection && doc.selection.createRange) {
var range = doc.selection.createRange();
if (range.pasteHTML) {
range.pasteHTML("<b>Some bold text</b>");
}
}
UPDATE
In IE 11, document.selection
is gone and insertHTML
is still not supported, so you'll need something like the following:
https://stackoverflow.com/a/6691294/96100
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…