Ckeditor chose html not working correctly with Chrome browser

Iam works in the mvc application and uses ckeditor version 3.6.2. I used the following code to get the selected html from ckeditor.

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; } }; 

I have a problem in the Chrome browser when I select the text and call CKEDITOR.instances.editor1.getSelectedHtml ().

For example, suppose my editor has the content <span style = "color: red;" > Welcome Note </span>. If I select "Welcome Note" and call the getSelectedHtml () method firefox, safari, IE8 will return a "greeting" with the span tag, but chrome will only return the text "Welcome Note". If Iam tries to replace the selected content using CKEDITOR.instances.editor1.insertHtml ("<div style = 'font-size: 12px'>" + CKEDITOR.instances.editor1.getSelectedHtml () + "</div>"), in chrome I lost the font color since getSelectedHtml () returns only the selected text. But this works great with other browsers.

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

Please suggest the right solution.

+8
javascript jquery asp.net-mvc ckeditor
source share
1 answer

There were some similar cases that are described on the CKEDITOR website. In particular, take a look at this:

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

+1
source share

All Articles