Search code examples
phpjavascripttinymcerte

how to add multiple tinyMce with dom javascript?


Please help me, how to add multiple textarea wit tinymce ..! I wanted to like this result:

examples of my scripts is here: http://tuto-rial.com/index2.txt

enter image description here


Solution

  • For this you will need to use two separate tinymce init functions. I guess you have two textareas at your page at the beginning. The first one gets activated on page load using an init like this:

    $(document).ready(function() {
        tinyMCE.init({
            // General options
            mode:      "exact",
            elements : "id_of_first_textarea",
            ...
        });
    });
    

    On "Add new"-buttonclick you do the following:

    tinyMCE.init({
        // General options
        mode:      "exact",
        elements : "id_of_second_textarea",
        // deactivates the editor body
        setup : function(ed) {
            ed.onInit.add(function(ed, evt) {
                // you may also add a click handler here to disable the focus of the editor body
                $(ed.getBody()).attr('contenteditable', false);
            }); 
        },
        ...
    });
    

    The "Get Content" buttonaction does the following:

    var content = tinymce.get('textarea_id_of_the_desired_editor').getContent();