how to set tinymce default content

心不动则不痛 提交于 2019-12-10 11:29:11

问题


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>');

Thanks a lot.


回答1:


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.

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.

E.g.

tinymce.init({
    ...
    init_instance_callback: "insert_contents",
});


function insert_contents(inst){
    inst.setContent('<strong>Some contents</strong>');  
}


来源:https://stackoverflow.com/questions/16508001/how-to-set-tinymce-default-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!