在创建实例后,通过JavaScript更新CKEditor的CSS

时间:2012-02-02 16:49:23

标签: javascript css ckeditor

我创建一个像这样的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>

2 个答案:

答案 0 :(得分:3)

尝试了很多不同的事情并最终得到了这个:

<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>

答案 1 :(得分:1)

您可以使用以下内容:

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

你的编辑器ID是,你猜对了,编辑器的ID,0是你的样式表的索引。