Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set tinymce default content

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.

like image 758
Jasper Avatar asked Sep 13 '25 10:09

Jasper


1 Answers

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>');  
}
like image 98
migreva Avatar answered Sep 17 '25 18:09

migreva