有没有办法点击离开ckeditor,它会保存内容然后关闭

Is there a way to click away from ckeditor and it saves the contents and then closes?

本文关键字:保存 然后 ckeditor 离开 有没有      更新时间:2023-09-26

我使用 CKEditor 作为我的文本编辑器。我想知道是否有办法单击远离编辑器(即屏幕上的任何其他位置),然后保存其中的内容?

当然 - 挂接到编辑器的 blur 事件,并向 Save 处理程序发出 AJAX 请求。

// initialise
var editor = CKEDITOR.replace( 'editor1' );
// hook up blur
editor.on('blur', function(){
    var text = this.getData();
    $.ajax('/Save', {
        method: 'POST',
        data: { 
            content: text
        },
        dataType: 'json'
    }).done(function(){
         ...
    }).fail(function(){
         ...
    }).always(function(){
         ...
    });
});

http://jsfiddle.net/daveSalomon/sqbd2vjh/

相关文章: