If you want to load content into TinyMCE as a page loads you can use the setContent
function to do that ... but you need to make sure that TinyMCE is initialized before you try to use setContent
.
The best way to do that is to put the code to load the content into the configuration object for TinyMCE. For example:
tinymce.init({
...
setup: function (editor) {
editor.on('init', function () {
var dataFromLS = <code to get the HTML from local storage>;
this.setContent(dataFromLS);
});
}
...
});
The basic way to use setContent()
is just to pass the HTML to is as the only parameter of the method. If you have the data in local storage just grab that first into a JS variable and then do something like this:
var dataFromLS = <code to get the HTML from local storage>;
tinymce.get('wo_scope').setContent(dataFromLS);
Note that in the init example I provided above you can refer to the editor instance as this
. You can also get it based on the ID of the<textarea>
that you replace with TinyMCE. A more complete (correct) example could do something like this:
tinymce.get('wo_scope').setContent(datafromLS);
The setContent()
method works on a specific instance of TinyMCE so you need to have one before you can call setContent()
. My examples above show two ways to get that instance get()
and in the init using this
.
Note: In one of your comments above you use tinymce.activeEditor
- that only works if you have clicked into a TinyMCE editor instance - that makes it the "active" editor. If you are doing this on page load you almost certainly don't yet have an active editor.
:String
at the end just tells you that this function returns a string. See the "Returns" section at the end of the doc page. – Jason P