用内容初始化tinymce [英] initialize tinymce with content
问题描述
我有一个包含一个tinymce4编辑器实例的页面。我想用编程方式用一些内容初始化这个编辑器。我知道我必须打电话: tinymce.get('editor')。setContent('my content');
I have a page containing one tinymce4 editor instance. I want to initialize this editor with some content, programmatically. I know that I have to call: tinymce.get('editor').setContent('my content');
然而,当tinymce初始化时,我很难做到这一点。已经提出这个问题:使用默认内容初始化tinyMCE 但给出了答案那个时候不起作用,至少对于tinymce4来说。
However I have trouble to do this when tinymce is getting initialized. This question has already been asked: initialize tinyMCE with default content but the answer that was given at that time is not working, at least for tinymce4.
以下是我的尝试:
第一次尝试:
tinymce.init({
mode: "textareas",
...
setup: function (editor) {
...
editor.setContent('my content');
}
});
- >未捕获的TypeError:无法读取未定义的属性'body'
-> Uncaught TypeError: Cannot read property 'body' of undefined
第二次尝试:
tinymce.init({
mode: "textareas",
...
};
tinymce.get('editor').setContent('my content');
- >未捕获的TypeError:无法读取null
的属性'setContent'(但是如果我在加载包含tinymce编辑器的页面时执行此操作,则可以正常工作) 。
-> Uncaught TypeError: Cannot read property 'setContent' of null (however if I do this when the page containing the tinymce editor has already been loaded, it works).
第3次尝试(SO 12083361答案):
3rd attempt (SO 12083361 answer):
$(document).ready(function(){
tinymce.get('editor').setContent('my content');
});
- >未捕获TypeError:无法读取属性'setContent'为null
-> Uncaught TypeError: Cannot read property 'setContent' of null
所有这些都失败了 tinymce.activeeditor.setContent('my content');
。
我应该在哪里放置 tinymce.get('editor')。setContent('我的同事ntent');
在我的代码中让它工作?
Where should I place tinymce.get('editor').setContent('my content');
in my code to have it working ?
推荐答案
对于版本4,你应该做它是这样的:
With version 4 you should do it like this:
tinymce.init({selector:'textarea'});
tinymce.activeEditor.setContent('custom');
这是小提琴。
这篇关于用内容初始化tinymce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!