How do I remove all tinymce instances at startup?
I'm dynamically creating and destroying textareas for this purpose. However, when I create a textarea and then an instance of it in tinymce--then come back to the page again, it doesn't work. I've found that the solution is to simply remove any exis开发者_高级运维ting instance of that same name, but I was wondering if it's possible to just do it at startup.
Thanks in advance!
You have to make sure that the textareas or other elements for which you create a tiny instance need to have different ids.
To remove all tinymce instance you may use (tinymce3):
for (var i = tinymce.editors.length - 1 ; i > -1 ; i--) {
var ed_id = tinymce.editors[i].id;
tinyMCE.execCommand("mceRemoveControl", true, ed_id);
}
For tinymce4 use:
for (var i = tinymce.editors.length - 1 ; i > -1 ; i--) {
var ed_id = tinymce.editors[i].id;
tinyMCE.execCommand("mceRemoveEditor", true, ed_id);
}
Make sure to shut down instances the right way when you try to reinitialize a tinymce instance. Otherwise your editor window could stay white or it is not editable at all.
For me works this solution:
tinymce.editors = [];
So, you can clear the editors array first and reinitialize the editor with init:
tinymce.editors = [];
tinymce.init({
selector: 'textarea.tinymce',
...
});
My colleague Beni discovered a smart solution to remove all existing TinyMCEs:
if(typeof(tinyMCE) !== 'undefined') {
var length = tinyMCE.editors.length;
for (var i=length; i>0; i--) {
tinyMCE.editors[i-1].remove();
};
}
This is what I'm using and appears to work fine:
while (tinymce.editors.length > 0) {
tinymce.remove(tinymce.editors[0]);
}
TinyMCE V5
Remove all instances with:
tinymce.remove();
More info see this.
You can use these lines in onload function of javascript or on saving form of previous instance
if (tinyMCE.getInstanceById(id) != null)
{
tinyMCE.execCommand('mceRemoveControl', true, id);
}
where id is the id of textarea or input on which the tinyMce is present
精彩评论