Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get formatted HTML from CKEditor

I'm using CKEditor in my web app, and I'm at a loss as to how to get the contents of the editor with HTML formatting.

var objEditor = CKEDITOR.instances["sectionTextArea"]; var q = objEditor.getData(); 

This will get me the text entered in CKEditor, without any markup.

However,

var q = objEditor.getHTML(); 

will return a null value. What am I doing wrong?

like image 361
sslepian Avatar asked Mar 14 '10 00:03

sslepian


2 Answers

getHTML isn't a method of a CKEditor object, so instead of null you should have a javascript error.

The method defined by the api is getData() if that doesn't work then you have some other problem in your code, try to use an alert to verify the contents at that moment.

like image 132
AlfonsoML Avatar answered Oct 19 '22 04:10

AlfonsoML


just to know that the right method for this is getData() didn't help me. I did not know how to use it on the CKEditor object. and CKEDITOR.getData() doesn't work.

this is how getData() is used on the CKEDITOR object:

CKEDITOR.instances.my_editor.getData() 

...where my_editor is the id of your textarea used for CKEditor.

The opposite of it is setData():

CKEDITOR.instances.my_editor.setData("<p>My Text</p>"); 
like image 33
low_rents Avatar answered Oct 19 '22 04:10

low_rents