如何设置tinymce默认内容 [英] how to set tinymce default content
问题描述
我的tinymce版本是3.5.8。我想设置默认内容,并尝试在官方网站上使用google等方法,但都出错了。某些错误如下:
My tinymce version is 3.5.8. I want to set the default content, and try the way on official website and other ways by google, but all error. Some of error as below:
TypeError: tinyMCE.activeEditor is null
[Break On This Error]
tinyMCE.activeEditor.selection.setContent('<strong>Some contents</strong>');
TypeError: tinyMCE.get(...) is undefined
[Break On This Error]
tinyMCE.get('content').setContent('<strong>Some contents</strong>');
非常感谢。
推荐答案
这可能是因为tinyMCE编辑器尚未初始化。如果您运行tinyMCE.init()函数,则在脚本中尝试执行setContent调用后,它将失败,因为init()函数仍在运行。
This is likely because the tinyMCE editor has not been initialized yet. If you run your tinyMCE.init() function then right after in the script try to do a setContent call, it will fail because the init() function is still running.
您可以做的是指定 init_instance_callback ,将在tinyMCE编辑器初始化后运行。在此回调中运行setContent调用将成功设置编辑器的内容。
What you can do is specify an init_instance_callback, which will run after the tinyMCE editor is initialized. Running your setContent call in this callback will successfully set the content of the editor.
例如
tinymce.init({
...
init_instance_callback: "insert_contents",
});
function insert_contents(inst){
inst.setContent('<strong>Some contents</strong>');
}
这篇关于如何设置tinymce默认内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!