TinyMCE 4 - remove() or destroy()

不问归期 提交于 2019-12-18 11:08:51

问题


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.


回答1:


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



回答2:


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




回答3:


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();



回答4:


The following code is working

tinymce.get(id).remove();



回答5:


Simply use

tinymce.remove()

to remove all editors.




回答6:


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




回答7:


You need simply use this code in order to remove all the editable textarea:

tinyMCE.remove(".editable");

Here more info about tinyMCE remove: http://archive.tinymce.com/wiki.php/api4:method.tinymce.EditorManager.remove.static




回答8:


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.




回答9:


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




回答10:


Little late to the party but I recently added tinyMCE jQuery version to my angular project. For a few reasons I did not want to use the angular 3rd party code and just wanted the jQuery version to work.

So here is my code for making TinyMCE 4.x work in angular, even with ng-repeat.

All you have to do is decorate your textareas with the class "TinyMCEEditorBox" and call this method anytime you remove or add items that result in an update (such as more items being added to an ng-repeat).

$scope.RebindTinyMCE = function ()
{
    var tmceSelector = ".TinyMCEEditorBox";

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

    setTimeout(function () {
        $(tmceSelector).tinymce({
            menubar: false,
            statusbar: false,
            toolbar: 'bold italic underline | alignleft aligncenter alignright | bullist numlist outdent indent | link',
        });
    }, 50);
}



回答11:


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




回答12:


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




回答13:


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'});
}



回答14:


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;
    }
  }
}


来源:https://stackoverflow.com/questions/17759111/tinymce-4-remove-or-destroy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!