initialize tinyMCE with default content

2019-02-27 19:38发布

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

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

I've tried tinyMCE.execCommand(), but that doesn't work either.

I want the JavaScript function to initialize the textarea with data stored in localStorage, which I have checked, is working fine. Any suggestions?

1条回答
Emotional °昔
2楼-- · 2019-02-27 20:12

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

document.ready=function(){
   //debug document.getElementById('mainbuffer') return not undefined?
   tinyMCE.get('mainbuffer').setContent( localStorage.getItem('mainbuffer') );
}
查看更多
登录 后发表回答