initialize tinyMCE with default content

痞子三分冷 提交于 2019-12-02 09:49:32

问题


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:


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') );
}


来源:https://stackoverflow.com/questions/12083361/initialize-tinymce-with-default-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!