TinyMCE 4 - remove() or destroy()

后端 未结 15 594
抹茶落季
抹茶落季 2020-12-25 12:22

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.

Bu

相关标签:
15条回答
  • 2020-12-25 12:36

    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();
    
    0 讨论(0)
  • 2020-12-25 12:36

    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')]

    0 讨论(0)
  • 2020-12-25 12:40

    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

    0 讨论(0)
  • 2020-12-25 12:43

    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

    0 讨论(0)
  • 2020-12-25 12:47

    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');
    
    0 讨论(0)
  • 2020-12-25 12:47

    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;
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题