TinyMCE 4 - remove() or destroy()

2020-02-19 07:10发布

I am using TinyMCE editor. I want to remove or destroy tinymce editors (Page contain more then one editor). Also remove classes and IDs added by tinyMCE.

But leave editable contents

I tried :

tinymce.remove()
tinymce.destroy()
tinymce.execCommand('mceRemoveControl',true,'.editable');

Please note:

my editor class is .editable, And I have more then one editors in my page.

14条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-02-19 07:31

Just in case anybody arrived here who is using the jQuery version of TinyMce use the following instead to remove an instance:

$("#textarea_id").tinymce().remove();
查看更多
趁早两清
3楼-- · 2020-02-19 07:38

The following code is working

tinymce.get(id).remove();
查看更多
走好不送
4楼-- · 2020-02-19 07:40

If you have multiple Instances of TinyMCE you can use following code snippet to close every instance of TinyMCE:

for (var i = tinymce.editors.length - 1 ; i > -1 ; i--) {
    var ed_id = tinymce.editors[i].id;
    tinyMCE.execCommand("mceRemoveEditor", true, ed_id);
}

I use it before the Ajax Content is loaded.

查看更多
劳资没心,怎么记你
5楼-- · 2020-02-19 07:41

Bear in mind that if given textarea has an id, tinyMCE will use it for some strange reason, even if selector parameter has been used to apply editor to given element. This id is then used in internal array - tinyMCE.editors which isn't cleared (isn't cleared if you'll use tinymce.execCommand('mceRemoveControl', true, [id]), remove actually removes editors and prevents tinyMCE to be applied ever again). As such if you have a dynamic content with tinyMCE applied, it will work once, but never again. To resolve this you need to clean this array manually per delete tinyMCE.editors[$(node).getAttribute('id')]

查看更多
一夜七次
6楼-- · 2020-02-19 07:43

we were getting error on calling
elementReference.destroy() // destroy is a dojo function
we replaced that code with
elementReference.domNode.remove()
we were also using tinymce.min.js, and it was giving us NS_ERROR_UNEXPECTED

查看更多
等我变得足够好
7楼-- · 2020-02-19 07:44

tinymce.EditorManager.remove() This was working for me

查看更多
登录 后发表回答