Reputation: 61
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.
Upvotes: 4
Views: 13016
Reputation: 876
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>');
}
Upvotes: 16