How do I initialize TinyMCE on a ajax loaded textarea in 4.x?

折月煮酒 提交于 2019-12-18 03:57:27

问题


I am upgrading to tinyMCE 4.x and I am attempting to initialize tinyMCE on a textarea loaded via AJAX. In 3.x I did something of the sort: TinyMCE - attach to divs loaded via AJAX calls but this does not seem to work in 4.x.


回答1:


tinymce.remove();
tinymce.init();

This works well!




回答2:


In TinyMCE 4.x mceRemoveControl and mceAddControl have been removed. You have to use mceRemoveEditor and mceAddEditor instead.

Got it from: [Resolved] mceRemoveControl and mceAddControl in tinymce 4

Otherwise, you can reload tinymce.init({ ... }) but that should not be the way as it would be slower.




回答3:


You can load TinyMCE after including textarea with the following code:

//initialize tinyMCE in page
tinymce.init({selector:'textarea'});



回答4:


just for then running into the same problem.

I solved the problem with wrapping the init Script into a function like this.

in my init.js file

initializeTinyMce();
function initializeTinyMce(selector){
  if(selector == undefined){selector = 'textarea';}
  ...
  tinymce.init({
    selector: selector,
    ...
  });
}

so on your ajax request result you add

<script type="text/javascript">
  $(document).ready(function(){
    initMCE('textarea#someId');
  });
</script>

works fine for me




回答5:


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

just use this in ajax and if you are not able to pick the value then Before submitting the form, call

tinyMCE.triggerSave();



来源:https://stackoverflow.com/questions/19568238/how-do-i-initialize-tinymce-on-a-ajax-loaded-textarea-in-4-x

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