Copy text (HTML) to CKeditor

28.Jul.2010

In case you want to copy text (or HTML) to CKeditor on your form using JavaScript, you should use following snippet:

1
2
var oEditor = CKEDITOR.instances['entity_id'];
oEditor.setData( some_text_to_copy_to_ckeditor );

To copy HTML from CKeditor:

1
2
var objEditor = CKEDITOR.instances['entity_id'];
var some_html_value_from_ckeditor = objEditor.getData();

At last, if you would like to append text (or HTML) to CKeditor, use combination of code above as shown in snippet:

1
2
var objEditor = CKEDITOR.instances['entity_id'];
oEditor.setData( objEditor.getData() + some_text_to_copy_to_ckeditor );