最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to detect CKEditor source mode on change event - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Jun 28, 2013 at 6:02 user7180user7180 4,0662 gold badges23 silver badges26 bronze badges 3
  • Have a look at this question: stackoverflow.com/questions/5230839/… – Mimo Commented Jun 28, 2013 at 6:05
  • Thanks @Kicker for the tips, on key works for the source view as well – user7180 Commented Jun 28, 2013 at 6:21
  • That first statement is wrong: Currently CKEditor doesn't fire by itself any change event at all. You must be using some plugin that takes care of it, but it only works in "normal mode" as you call it. – AlfonsoML Commented Jun 28, 2013 at 9:41
Add a comment  | 

2 Answers 2

Reset to default 13

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

Thanks for Kicker's hint

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)

  1. 暂无评论