0

CKEditor 4.x makes it very easy to grab the contents of the textarea html:

var data = CKEDITOR.instances.editor1.getData();

...but very difficult to intercept the Save event (or whatever happens when clicking their built-in save icon on the toolbar). By default, it does a form post. I simply want to prevent the form post and grab the contents, as in the js line above. After scouring their documentation and various stack posts -- and after trying different approaches -- it seems this basic functionality is difficult to achieve or closely guarded.

How is it done?

Community
  • 1
  • 1
HerrimanCoder
  • 6,835
  • 24
  • 78
  • 158

1 Answers1

0

I finally found the answer:

<script>
   var ckEditor = CKEDITOR.replace('editor1');

   ckEditor.on("instanceReady", function () {
      // overwrite the default save function
      ckEditor.addCommand("save", {
         modes: { wysiwyg: 1, source: 1 },
         exec: function () {
            var theData = ckEditor.getData(); // get the editor content
            console.log(theData);
         }
      })
   });
</script>
HerrimanCoder
  • 6,835
  • 24
  • 78
  • 158