CKEditor:通过 Javascript 切换到源代码视图

CKEditor : Switching to Source View via Javascript

我需要一种方法让我的 CKEditor 通过配置选项加载到 'Source' 视图,或者能够通过 javascript 方法将其设置到 'Source' 视图。

默认情况下,CKEditor 加载到 WYSIWYG 视图,但我需要默认显示 HTML。

我已经搜索了这里的档案以及 CKEditor 上的开发人员文档,但我没有找到我的答案。

您可以收听例如准备就绪并触发源模式的命令

CKEDITOR.replace('editor1');    
CKEDITOR.on("instanceReady", function(event) {
    event.editor.commands.source.exec();
});

http://jsfiddle.net/wa81Lrny/1/

你要的是config.startupMode

The mode to load at the editor startup. It depends on the plugins loaded. By default, the wysiwyg and source modes are available.

config.startupMode = 'source';