删除TinyMCE控件并重新添加

Fla*_*ape 7 html javascript state tinymce

我有一个永远不会重新加载页面的js应用程序,因此在导航时我需要完全删除TinyMCE控件,然后我想在导航到需要它的区域时重新初始化.我尝试了这个问题的接受答案,但似乎什么也没做.

如何删除tinyMCE然后重新添加?

 tinymce.EditorManager.execCommand('mceRemoveControl',true, editor_id);
Run Code Online (Sandbox Code Playgroud)

和我的具体意见:

  //if I throw an alert here, it does get called, so I know it's not null
  if (tinyMCE.getInstanceById("main-text"))
            tinyMCE.EditorManager.execCommand('mceRemoveControl', true, "main-text");
Run Code Online (Sandbox Code Playgroud)

我也试过了

  tinyMCE.remove( tinyMCE.getInstanceById("main-text"));
  // AND
  tinyMCE.remove( "main-text");
Run Code Online (Sandbox Code Playgroud)

我知道当我在条件中发出警报时,该语句会被执行...我知道这是正确的ID-- API中是否还有其他内容我缺少?这不是jQuery版本.编辑器在删除尝试后仍然存在,如果我通过导航回到具有该表单的状态重新启动它,我甚至会获得具有相同ID的新编辑器.

编辑:下面的解决方案在当前版本3.5b3中不起作用,仅在3.4.9中.有一个'未定义'的错误

以防万一,这是init之后DOM的相关部分.

 <textarea id="main-text" style="display: none;" aria-hidden="true"></textarea>
<span id="main-text_parent" class="mceEditor defaultSkin" role="application" aria-labelledby="main-text_voice" style="display: inherit;">
<span id="main-text_voice" class="mceVoiceLabel" style="display:none;">Rich Text Area</span>
<table id="main-text_tbl" class="mceLayout" cellspacing="0" cellpadding="0" role="presentation" style="width: 100%; height: 400px;">
<tbody>
<tr class="mceFirst" role="presentation">
<td class="mceToolbar mceLeft mceFirst mceLast" role="presentation">
<div id="main-text_toolbargroup" aria-labelledby="main-text_toolbargroup_voice" role="group" tabindex="-1">
<span role="application">
</div>
<a onfocus="tinyMCE.getInstanceById('main-text').focus();" title="Jump to tool buttons - Alt+Q, Jump to editor - Alt-Z, Jump to element path - Alt-X" accesskey="z" href="#"></a>
</td>
</tr>
<tr>
<tr class="mceLast">
</tbody>
</table>
</span>
Run Code Online (Sandbox Code Playgroud)

Sha*_*ank 21

任何遇到这篇文章的人.现在,只需调用remove函数,tinymce 4.X就支持删除编辑器或编辑器表单页面.

http://www.tinymce.com/wiki.php/api4:method.tinymce.remove

// Remove all editors bound to divs
tinymce.remove('div');

// Remove all editors bound to textareas
tinymce.remove('textarea');

// Remove all editors
tinymce.remove();

// Remove specific instance by id
tinymce.remove('#id');
Run Code Online (Sandbox Code Playgroud)


Pat*_*cia 5

我已经碰到了几次.为了解决这个问题,我确保tinyMCe控件没有焦点(在某些浏览器中导致一些错误),删除tinyMCE控件,并删除与控件关联的文本区域.

这是相关的代码:

if (typeof tinyMCE != 'undefined') {
    tinyMCE.execCommand('mceFocus', false, 'main-text');
    tinyMCE.execCommand('mceRemoveControl', false, 'main-text');
    var container = document.getElementById('main-text-parent');
    container.removeChild(document.getElementById('main-text'));  
    //i normally just do $("#main-text").remove(); but you specified not using jquery, so this should, in theory, remove it, if main-text-parent is replaced with the parent container of your main-text.
}
Run Code Online (Sandbox Code Playgroud)