how to set text in ckeditor

user1528884 picture user1528884 · Feb 10, 2013 · Viewed 12.6k times · Source

How do I set text in CKEditor? CKEditor also needs to integrate with ckfinder.

I tried doing

// I need to set ckeditor text with a value in code behind. To get that value from code bhind, I am using a div which would be set in code behind. This is not hidden currently but I would do that eventually. I need to set this value to my ckeditor.

    <textarea id="editor1" name="editor1"></textarea>
        <script type="text/javascript">
            window.onload = function () {

                    var edt = CKEDITOR.replace('editor1', { toolbar: 'Basic' });
 CKFinder.setupCKEditor(edt, '/ckfinder/');

                    var t = <%=editortext.InnerText %>;


                    CKEDITOR.instances.editor1.setData(t);

            }

If I put some static text for t, var t = "Some Text";

and then set

CKEDITOR.instances.editor1.setData(t); it works fine.

If I use,

var t = <%=editortext.InnerText %>;


                    CKEDITOR.instances.editor1.setData(t);

ckeditor is no longer displayed. Only text area is displayed. How to set text in ckeditor ? Please help

Answer

Web Developer in Pune picture Web Developer in Pune · May 27, 2013

This syntax may be useful here:

CKEDITOR.instances['editor1'].setData(t); // where editor1 is id

OR try this

edt.setData(t);