How to detect CKEditor source mode on change event

99封情书 提交于 2019-12-21 04:00:33

问题


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("ckeditor on change");
});

But if I switch over to the source mode, the event does not fire.

How can I detect the on change event for source view?


回答1:


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

Thanks for Kicker's hint




回答2:


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.
        });
    }
});


来源:https://stackoverflow.com/questions/17358203/how-to-detect-ckeditor-source-mode-on-change-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!