Initialize tinyMCE with default content

I have a quick question about tinyMCE . I have textarea, with id="mainbuffer" and the tinyMCE.get(id).setContent(data) function.

ONLY works when it is called onclick="function()" from the link and does not work when the page loads. In my case, this is: tinyMCE.get('mainbuffer').setContent( localStorage.getItem('mainbuffer') );

I tried tinyMCE.execCommand() , but this does not work either.

I want the JavaScript function to initialize the text field with the data stored in localStorage, which I checked, works fine. Any suggestions?

+1
source share
1 answer

If you want to put the script on the page load, make sure you put your code in document.ready or after TinyMCE and your item have been loaded.

 document.ready=function(){ //debug document.getElementById('mainbuffer') return not undefined? tinyMCE.get('mainbuffer').setContent( localStorage.getItem('mainbuffer') ); } 
+1
source

Source: https://habr.com/ru/post/1206547/


All Articles