CKEditor Embed HTML

  • I have data from a database.
  • In my js file, I would like to change the value of the CKEditor text editor.
  • My value is raw html.
  • I want this raw value to be written to an empty CKEditor text editor.

I tried them, but got a undefined functional error all the time:

CKEDITOR.instances.myEditorID.insertHtml( '<p>This is a new paragraph.</p>' ); CKEDITOR.instances.myEditorID.setData( '<p>This is the editor data.</p>' ); 

I tried this too, but the function error is still undefined:

 CKEDITOR.instances.YOUREDITORID.updateElement(); alert( document.getElementById( 'YOUREDITORID' ).value ); 

Instead of myEditorID I tried 'editor', 'editor1', 'editor2', but still does not work for me.

Thanks in advance.

--- Update ---

This is the html of my ckeditor text editor:

 <textarea id="myEditorID" name="myEditor"></textarea> <script type="text/javascript"> $(function () { var myEditor = $('#myEditorID'); myEditor.ckeditor({ height: 200, extraPlugins: 'charcount', maxLength: 2000, toolbar: 'TinyBare', toolbar_TinyBare: [ ['Bold','Italic','Underline'], ['Undo','Redo'],['Cut','Copy','Paste'], ['NumberedList','BulletedList','Table'],['CharCount'] ] }).ckeditor().editor.on('key', function(obj) { if (obj.data.keyCode === 8 || obj.data.keyCode === 46) { return true; } if (myEditor.ckeditor().editor.document.getBody().getText().length >= 2000) { alert('You have reached the maximum char length'); return false; } }); }); </script> 
+6
source share
1 answer

Instead of myEditorID I tried 'editor', 'editor1', 'editor2', but still not working for me.

You need to look at the HTML page of your page and see which ID field is for your editor. It will be something like this

 <textarea id="my_editor"></textarea> 

This id attribute is what you need to do here

 CKEDITOR.instances.my_editor.insertHtml('<p>This is a new paragraph.</p>'); 
+7
source

Source: https://habr.com/ru/post/980592/


All Articles