Tinymce 4.2.0 got Cannot read property 'setContent' of null

匿名 (未验证) 提交于 2019-12-03 02:34:02

问题:

I got Cannot read property 'setContent' of null, when i want to using setContent function. Intended for set value in text editor generated by Tinymce library. Is am wrong to implemented it?Below is my snippet code:

<textarea name="content"></textarea>       <script src="assets/tinymce/tinymce.min.js"></script> <script>   tinymce.init({     selector:'textarea'   });             tinymce.activeEditor.setContent('custom'); </script>     

Does anyone knows about this problem? Thanks! any effort would be appreciated

回答1:

You have to wait until the editor is initialized:

tinymce.init({   selector:'textarea',   init_instance_callback : function(editor) {     editor.setContent('custom');   } }); 


回答2:

There is other turn around for your solution:

Call setContent within $( window ).load(function(){}) but you have initialize jquery first.

Modified code will look like below:

<textarea name="content"></textarea>       <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="assets/tinymce/tinymce.min.js"></script> <script>   tinymce.init({     selector:'textarea'   });  $( window ).load(function(){            tinymce.activeEditor.setContent('custom'); }); </script>   


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