How to detect CKEditor source mode on change event

前端 未结 2 1349
不知归路
不知归路 2021-02-08 00:38

In CKEditor, I know that in the \"normal mode\", we can detect any content change using the following code:

ckeditor.on(\'change\',function(e){
  console.log(\"c         


        
相关标签:
2条回答
  • 2021-02-08 00:54

    The CKEditor 4 documentation tells that the change event won't be fired in source mode.

    The example from the documentation worked for me. It binds a listener to the mode event. That's fired when the mode changes. When it changes to source, attach a listener to the editor.

    editor.on('mode', function() {
        if (this.mode === 'source') {
            var editable = editor.editable();
            editable.attachListener(editable, 'input', function() {
                // Handle changes made in the source mode.
            });
        }
    });
    
    0 讨论(0)
  • 2021-02-08 01:08

    Instead of using "change" event, the "key" event does fire on the source view.

    Thanks for Kicker's hint

    0 讨论(0)
提交回复
热议问题