Displayin tinyMCE after twice ajax call

℡╲_俬逩灬. 提交于 2019-12-12 04:28:30

问题


In my page, when a button is clicked, a div appears which has a textarea(tinyMCE). I have a close button for that div. When I open the div, do my job, close the div, and open the div again, tinyMCE editor doesn't appear. Here is the summary of my problem 1-) Click button, onclick="doAjax()" and display the returned value in a DIV 2-) In that DIV, there is a textarea with tinyMCE. Everything is OK 3-) Close the div(in fact, just fadeOut() the DIV) Everything is OK 4-) Click the button on step 1 again, onclick="doAjax()" and display the returned value in a DIV 5-)In that DIV, THERE IS NOT A TEXTAREA WITH TINYMCE! I tried using some of them but couldn'T make it work

if (tinyMCE.get === 'undefined')
{
   tinyMCE.execCommand('mceRemoveControl', false, 'message');
    tinyMCE.execCommand('mceAddControl', false, 'message');
 }

This code shows tinyMCE only for the first time, not for the second or later. Any solutions?

-----------------------SOLUTION---------------------------------- Okey. I found a solution

var oldEditor = tinyMCE.get('message');
if (oldEditor != undefined) {
     tinymce.remove(oldEditor);
}
tinyMCE.execCommand('mceAddControl', false, 'message');

That works fine!


回答1:


came across the same problem and solved it by basically removing all of the instances before initializing it again

tinymce.remove();
tinymce.init({selector: 'textarea'});



回答2:


I have posted your comment as an answer.

var oldEditor = tinyMCE.get('message');
if (oldEditor != undefined) {
    tinymce.remove(oldEditor);
}
tinyMCE.execCommand('mceAddControl', false, 'message');

Always consider taking some time and posting the answer if you found it.

Thanks,
Sworoop



来源:https://stackoverflow.com/questions/7434933/displayin-tinymce-after-twice-ajax-call

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