4

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.

Jasper
  • 61
  • 1
  • 2
  • 3
  • I just find a method to fix the default content. Just add both name and id to the textarea, then you can put the content between tag textarea, and the content will be show. – Jasper May 12 '13 at 14:02

1 Answers1

16

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>');  
}
Pakpoom Tiwakornkit
  • 2,601
  • 1
  • 20
  • 19
migreva
  • 877
  • 11
  • 18