how to set tinymce default content

2019-05-29 00:09发布

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条回答
够拽才男人
2楼-- · 2019-05-29 00:50

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>');  
}
查看更多
登录 后发表回答