更新CKEditor'在实例已经创建之后,通过JavaScript创建的CSS

Update CKEditor's CSS via JavaScript after instance is already created

本文关键字:创建 之后 通过 JavaScript CSS CKEditor 实例 更新      更新时间:2023-09-26

我创建了一个CKEditor实例,如下所示:

include 'ckeditor/ckeditor.php';
$CKeditor = new CKeditor();
$CKeditor->basePath = './ckeditor/';
$config = array();
echo '<textarea name="content" id="content"></textarea>';
$config['contentsCss'] = 'style1.css';
$config['ImageUpload'] = false;
$config['toolbar'] = 'Basic';
$events = array();
$CKeditor->replace('content', $config, $events);

现在,当这个实例已经创建时,我想通过JavaScript更改一些配置细节(例如"contentsCss")。这可能吗?

我的想法是(不幸的是,这不起作用):

<a href="#" onclick="CKEDITOR.instances.content.config.toolbar = 'Full'; return false;">change toolbar style</a>

尝试了很多不同的东西,结果是:

<script type="text/javascript">
function updateCKEditor() {
    var editor = CKEDITOR.instances.content;
    if (editor) {
        editor.destroy(true);
    }
    var newConfig = { skin : XYZ, toolbar : 'Basic', contentsCss : '' };
    CKEDITOR.replace('content', newConfig);
}
</script>

您可以使用这样的东西:

CKEDITOR.instances.yourEditorsId.window.$.document.getElementsByTagName("link")[0].href = 'new/path/style.css';

您猜到了,您的EditorsId所在的位置是编辑器的ID,0是样式表的索引。