How can I remove all instances of tinymce at startup?

advertisements

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 existing 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.