CKeditor只读内联编辑器

时间:2016-10-06 08:31:51

标签: javascript ckeditor

我使用ckeditor的内联编辑器来创建html内容。如何使其只读取并仅显示预览模式的内容。我尝试了以下配置但它对我不起作用。

this.editorInstance.setReadOnly( true); 

这里this.editorIntance是我的编辑。我想只显示预览模式的内容,不想显示编辑器的工具栏。

1 个答案:

答案 0 :(得分:1)

使用以下脚本使CKeditor只读。通过' true'或者' false' toggleReadOnly函数中的参数,用于禁用或启用ckeditor。

var editor;

// The instanceReady event is fired when an instance of CKEditor has finished
// its initialization.
CKEDITOR.on( 'instanceReady', function ( ev ) {
    editor = ev.editor;

    // Show this "on" button.
    document.getElementById( 'readOnlyOn' ).style.display = '';

    // Event fired when the readOnly property changes.
    editor.on( 'readOnly', function () {
        document.getElementById( 'readOnlyOn' ).style.display = this.readOnly ? 'none' : '';
        document.getElementById( 'readOnlyOff' ).style.display = this.readOnly ? '' : 'none';
    } );
} );

function toggleReadOnly( isReadOnly ) {
    // Change the read-only state of the editor.
    // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setReadOnly
    editor.setReadOnly( isReadOnly );
}

请参阅工作演示:https://jsfiddle.net/rbua57pq/3/

相关问题