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:21

Simply use

tinymce.remove()

to remove all editors.

查看更多
对你真心纯属浪费
3楼-- · 2020-02-19 07:22

Fake a virgin website

TinyMCE will check if its already loaded in window.scripts. If you remove the according entry TinyMCE will behave like it is a untouched document.

function cleanTinyMCE() {
  for (var i=0; i < window.scripts.length; i++) {
    if (window.scripts[i].match('.*tinymce.*js.*')){
      delete window.scripts[i];
      return;
    }
  }
}
查看更多
该账号已被封号
4楼-- · 2020-02-19 07:29

When using the tiyMCE.init({}) fuction, the answer by @nikmauro works for me, so for every unload of the page, you just trigger the tinymce.get("real_element_id").remove();

That method works for me.

BTW, I amusing this version

//tinymce.cachefly.net/4.1/tinymce.min.js 
查看更多
手持菜刀,她持情操
5楼-- · 2020-02-19 07:29

You need an editor id (which usually equals your editor html root elements id (in most cases a textarea)).

Example:

tinymce.execCommand('mceRemoveControl', true, 'my_original_textarea_id');
查看更多
Anthone
6楼-- · 2020-02-19 07:30

I had the same problem. In v4 all suggestions above did not work for me, but this did:

tinymce.remove("div.editable");

... regenerated HTML dynamicaly ...

tinymce.init(...);

I use inline editor:

tinymce.init({
    selector: "div.editable",
    inline: true,
    plugins: [
    "advlist autolink lists link image charmap print preview anchor",
    "searchreplace visualblocks code fullscreen",
    "insertdatetime media table contextmenu paste"
    ],
    menubar: false,
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"});

Hope this helped

查看更多
Explosion°爆炸
7楼-- · 2020-02-19 07:31
if (typeof tinyMCE != 'undefined') {
    if (tinyMCE.activeEditor == null || tinyMCE.activeEditor.isHidden() != false) {
        tinyMCE.editors=[]; 
    }
    tinyMCE.editors=[]; tinymce.init({selector:'textarea',  plugins : 'advlist autolink link image lists charmap print preview'});
}else{
    tinymce.init({selector:'textarea',  plugins : 'advlist autolink link image lists charmap print preview'});
}
查看更多
登录 后发表回答