问题
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