如何通过 CKeditor 中的 execCommand 将视图切换到所见即所得
How to switch view to wysiwyg via execCommand in CKeditor
上下文:我需要在插入照片后通过 javascript 执行操作(我正在尝试对 CKeditor 实施延迟加载,它提出了一些挑战!)。
此命令切换到源代码视图:
editor.execCommand( 'source' ); // works
此命令不切换到所见即所得视图:
editor.execCommand( 'wysiwyg' ); // does not work
正确的命令是什么?
这个有效:
editor.setMode( 'wysiwyg' );
(我使用的是 CKeditor 4.3)。
您可以通过两种形式更改模式:
- 启动模式
- 实例准备就绪后。
你可以使用这个例子
CKEDITOR.config.startupMode = 'source' // Set source as start mode
CKEDITOR.on("instanceReady", function(event) {
try {
// Make something with the editor in `source` mode
event.editor.setMode('wysiwyg'); // Change the mode to wysiwyg
} catch(error) {
console.log(error)
}
});
上下文:我需要在插入照片后通过 javascript 执行操作(我正在尝试对 CKeditor 实施延迟加载,它提出了一些挑战!)。
此命令切换到源代码视图:
editor.execCommand( 'source' ); // works
此命令不切换到所见即所得视图:
editor.execCommand( 'wysiwyg' ); // does not work
正确的命令是什么?
这个有效:
editor.setMode( 'wysiwyg' );
(我使用的是 CKeditor 4.3)。
您可以通过两种形式更改模式:
- 启动模式
- 实例准备就绪后。
你可以使用这个例子
CKEDITOR.config.startupMode = 'source' // Set source as start mode
CKEDITOR.on("instanceReady", function(event) {
try {
// Make something with the editor in `source` mode
event.editor.setMode('wysiwyg'); // Change the mode to wysiwyg
} catch(error) {
console.log(error)
}
});