gpt4 book ai didi

javascript - Ckeditor 选择的 html 在 chrome 浏览器中无法正常工作

转载 作者:数据小太阳 更新时间:2023-10-29 04:21:38 26 4
gpt4 key购买 nike

我正在使用 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;
}
};

当我选择文本并调用 CKEDITOR.instances.editor1.getSelectedHtml() 时,chrome 浏览器出现问题。

例如,假设在我的编辑器中有一个内容Welcome Note。如果我选择“Welcome Note”并调用 getSelectedHtml() 方法,firefox、safari、IE8 返回带有 span 标签的“Welcome Note”,但 chrome 仅返回文本“Welcome Note”。如果我尝试使用 CKEDITOR.instances.editor1.insertHtml("

"+ CKEDITOR.instances.editor1.getSelectedHtml()+"
") 替换所选内容,在 chrome 中,我丢失了字体颜色,因为 getSelectedHtml() 仅返回选定的文本。但这适用于其他浏览器。

Note : If the content is "Welcome <span style="color:red;">Note</span>" and the selected word is "Welcome Note". In this case,this will be correct in chrome and other browsers.

请提出合适的解决方案。

最佳答案

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

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

关于javascript - Ckeditor 选择的 html 在 chrome 浏览器中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10720166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com