Ropstah
Ropstah

Reputation: 17804

Safely 'print' raw html code in a textarea to use with CKeditor?

Which character do I need to replace to safely 'print' raw HTML code from a database in a textarea, so I can edit this with CKeditor?

Or is there another existing preferred method of getting data into a CKeditor textarea? (e.g. AJAX)

Upvotes: 1

Views: 1617

Answers (2)

user731144
user731144

Reputation: 25

Additionally you can now just take the variable that is returning the data from ajax or jquery and append it to the .setData(data).

Upvotes: 1

ZoogieZork
ZoogieZork

Reputation: 11279

CKEditor will use the initial contents of the textarea, so all you need to do is escape it as you normally would, e.g.:

<textarea id="editor1">&lt;p&gt;My &lt;strong&gt;bold&lt;/strong&gt; text&lt;/p&gt;</textarea>

See also CKEDITOR.replace.

If you want to set the contents of the textarea after CKEditor is loaded, use the setData API function:

CKEDITOR.instances.editor1.setData('<p>This is the editor data.</p>');

In both cases, CKEditor will load the raw HTML and do whatever preprocessing is necessary to make it work.

Upvotes: 4

Related Questions