views:

84

answers:

1

I'm building a wysiwyg-editor with an editable iframe using execCommands. Now i need to use the command 'insertHtml' which works perfect in Chrome and Firefox but of course it doesn't work in Internet Explorer.

What is the standard solution to this problem? It's okay if it only works in IE8 but IE7-support would be nice too.

+1  A: 

In IE 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>");
    }
}
Tim Down