Ckeditor选择html与chrome浏览器无法正常工作

Jay*_*raj 9 javascript asp.net-mvc jquery ckeditor

我在mvc应用程序中工作并使用ckeditor 3.6.2版本.我使用以下代码从ckeditor获取选定的html.

CKEDITOR.editor.prototype.getSelectedHtml = function () {

    if (CKEDITOR.env.ie) {
        this.focus();
        selection = this.getSelection();
    } else {
        selection = this.getSelection();
    }
    if (selection) {
        var bookmarks = selection.createBookmarks(),
     range = selection.getRanges()[0],
     fragment = range.clone().cloneContents();

        selection.selectBookmarks(bookmarks);

        var retval = "",
     childList = fragment.getChildren(),
     childCount = childList.count();
        for (var i = 0; i < childCount; i++) {
            var child = childList.getItem(i);
            console.log(child);
            retval += (child.getOuterHtml ?
        child.getOuterHtml() : child.getText());
        }
        return retval;
    }
};
Run Code Online (Sandbox Code Playgroud)

当我选择文本并调用CKEDITOR.instances.editor1.getSelectedHtml()时,我在chrome浏览器中遇到问题.

例如,假设在我的编辑器中有一个内容<span style ="color:red;"> Welcome Note </ span>.如果我选择"欢迎注意"并调用getSelectedHtml()方法firefox,safari,IE8返回带有span标记的"Welcome Note",但chrome只返回文本"Welcome Note".如果我尝试使用CKEDITOR.instances.editor1.insertHtml("<div style ='font-size:12px'>"+ CKEDITOR.instances.editor1.getSelectedHtml()+"</ div>")替换所选内容,在chrome中我丢失了字体颜色,因为getSelectedHtml()只返回选定的文本.但这适用于其他浏览器.

注意:如果内容为"Welcome <span style ="color:red;"> Note </ span>",则所选单词为"Welcome Note".在这种情况下,这在chrome和其他浏览器中是正确的.

请提出正确的解决方案.

Ace*_*Ace 0

CKEDITOR 网站上记录了一些类似的案例。特别是看一下这个:

http://cksource.com/forums/viewtopic.php?f=11&t=20202