0

I am using ck editor in my custom portlet.Liferay version 6.2 CE I want to place content in the caret position in ck editor with ajax call.

2 Answers2

1

You can use setData method from CKEditor's API for replace existing data:

$.ajax("url")
.done(function(data) {
    CKEDITOR.instances["<instance_name>"].setData(data);
});

For insert data into current caret position is method insertHtml:

$.ajax("url")
.done(function(data) {
    CKEDITOR.instances["<instance_name>"].insertHtml(data);
});

Good explanation for setting caret position is in this thread

Community
  • 1
  • 1
glw
  • 1,646
  • 1
  • 16
  • 20
  • Hi Thanks for reply, But this will remove the existing data in ck editor,and with setData how can caret position is set. – Krishna Mohan Mathakala Feb 05 '16 at 05:45
  • My question is How to get the caret position. – Krishna Mohan Mathakala Feb 06 '16 at 08:11
  • It is explained in that thread, getting/setting caret position using [ranges](http://docs.ckeditor.com/#!/api/CKEDITOR.dom.range). Using this `CKEDITOR.instances[""].getSelection().getRanges()` you have Object with information about selection, if nothing is selected, this information is about caret position (selection with length 0). – glw Feb 06 '16 at 09:40
0

Hi Thanks for the answer but. the Api is a bit different in Liferay compared with ck editor.

The methods insertHtml and get ranges are not there in Liferay ck editor