As the title says, I've looked up the official documentation but it ain't working; here's my JavaScript (utilizing jQuery) code:
$(document).ready(function() {
tinymce.init({
element_format: "html",
schema: "html4",
menubar: false,
plugins: 'preview textcolor link code',
selector: 'TEXTAREA#rtf',
toolbar: 'preview | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | blockquote subscript superscript | code'
});
tinymce.activeEditor.setContent($('TEXTAREA#rtf').text());
});
(Cough) Somehow, after I restored everything back to where I started now it works:
$(document).ready(function() {
tinymce.init({
element_format: "html",
menubar: false,
plugins: 'preview textcolor link code',
schema: "html4",
selector: 'TEXTAREA#rtf',
toolbar: 'preview | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | blockquote subscript superscript | code'
});
});
I suspect it was due to either the UA cache or the XSLT transformed result cache that made the issue; thanks again for your time!
How to setContent with multiple editors. Running the setContent() function on specifically editorOne with the tinymce. get('editorOne'). setContent(contentOne); method, you can change just editorOne.
To save the page, you have to insert TinyMCE in a HTML form and add a submit button. Then you'll have to handle the submitted form with a language like PHP. A call to the file_put_contents() function should do it.
This thread set me on the right track so I thought I'd share my solution with v4
tinymce.init({
...,
init_instance_callback:function(editor){
editor.setContent(__YOUR_CONTENT__);
}
});
I have found better solution that works anywhere in code (and is not a hack, unlike the setTimeout trick)
tinymce.get('tinymce-element-id').on('init',function(e) {
e.target.setContent('my custom content');
});
tinymce.activeEditor.setContent('<span>some</span> html');
https://www.tinymce.com/docs/api/tinymce/tinymce.editor/#setcontent
this is how I implemented it:
setTimeout(tinyMCE.init({
selector: "textarea.edit_notes",
height: editor_height,
theme: "modern",
menubar: "tools table format view insert edit",
force_br_newlines : false,
force_p_newlines : false,
forced_root_block : '',
//plugins: "fullpage",
valid_elements : '*[*]',
setup: function(ed){
ed.on("init",
function(ed) {
tinyMCE.get('testeditor').setContent($('#testeditor').val());
tinyMCE.execCommand('mceRepaint');
}
);
}
}), 50);
Give it a shot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With