'tinymce disappears and only plain text area is visible when I write setup function inside tinmyce.init()

Please see code below:

  tinymce.init({

      selector:"#editArea", //id of my textarea to be replaced by tinymce

      plugins : [
                  "advlist autolink link image lists charmap print preview textcolor colorpicker image imagetools contextmenu" ,
                  "autosave searchreplace wordcount insertdatetime code media nonbreaking spellchecker save table",
                  "directionality emoticons template paste visualblocks visualchars hr anchor pagebreak autoresize"

                  ],

       fontsize_formats: "8pt 9pt 10pt 11pt 12pt 26pt 36pt",            

      forced_root_block : '',
      schema: "html5",


      autosave_ask_before_unload:true,

      image_title: true,

      paste_data_images:true,


      toolbar: ["save undo redo styleselect  ", 
                    "alignleft aligncenter alignright emoticons",
                 " bullist  numlist outdent bold italic ",
                 " indent forecolor  backcolor code image",
                  "fontselect fontsizeselect"],


      contextmenu: "link image inserttable | cell row column deletetable",
      automatic_uploads: true,

      setup:function(ed){
            ed.onLoadContent.add(function(ed,o){
                o.content=o.content.replace(/Â/g,'');
            });
      }

});

Why tinymce editor disappears when the setup function is written (it is visible if I comment out the setup function part in above code)?



Solution 1:[1]

Which version of tinymce you are using?Please check if it supports ed.onLoadContent.add(function(ed,o){ o.content=o.content.replace(/Â/g,''); });

When I added this function to my tinymce init function..It worked well. Please find below code which works for me.

 tinyMCE.init({
        
        mode : "textareas",
        theme : "advanced",
        //plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        ////theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        ////theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        ////theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        theme_advanced_toolbar_location : "top",
        ////theme_advanced_toolbar_align : "left",
        ////theme_advanced_statusbar_location : "bottom",
        ////theme_advanced_resizing : false,
        ////template_external_list_url : "js/template_list.js",
        ////external_link_list_url : "js/link_list.js",
        ////external_image_list_url : "js/image_list.js",
       ////media_external_list_url : "js/media_list.js"

        setup: function (ed) {
            ed.onLoadContent.add(function (ed, o) {
                o.content = o.content.replace(/Â/g, '');
            });
        }
   });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 7ochem