I have a page containing one instance of the tinymce4 editor. I want to initialize this editor with some software. I know that I need to call: tinymce.get('editor').setContent('my content');
However, it is difficult for me to do this when tinymce initialization. This question has already been asked: initialize tinyMCE with default content , but the answer that was given at that time does not work, at least for tinymce4.
Here is what I tried:
First try:
tinymce.init({ mode: "textareas", ... setup: function (editor) { ... editor.setContent('my content'); } });
-> Uncaught TypeError: cannot read the 'body' property from undefined
Second attempt:
tinymce.init({ mode: "textareas", ... }; tinymce.get('editor').setContent('my content');
-> Uncaught TypeError: Cannot read the 'setContent' property from null (however, if I do this when the page containing the tinymce editor is already loaded, it works).
Third attempt (SO 12083361 answer):
$(document).ready(function(){ tinymce.get('editor').setContent('my content'); });
-> Uncaught TypeError: Unable to read setContent property from null
All this does not work with tinymce.activeeditor.setContent('my content'); .
Where can I put tinymce.get('editor').setContent('my content'); in my code to make it work?
source share