且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CKeditor 保存事件

更新时间:2022-06-12 06:22:21

你可以编辑常规保存按钮的功能来做你想做的事:

You can edit the functionality of the regular save button to do what you want:

html:

<textarea id="CKEditor1"></textarea>

javascript:

javascript:

<script>
    // Need to wait for the ckeditor instance to finish initialization
    // because CKEDITOR.instances.editor.commands is an empty object
    // if you try to use it immediately after CKEDITOR.replace('editor');
    CKEDITOR.on('instanceReady', function (ev) {

        // Create a new command with the desired exec function
        var overridecmd = new CKEDITOR.command(editor, {
            exec: function(editor){
                // Replace this with your desired save button code
                alert(editor.document.getBody().getHtml());
            }
        });

        // Replace the old save's exec function with the new one
        ev.editor.commands.save.exec = overridecmd.exec;
    });

    CKEDITOR.replace('CKEditor1');

</script>