5

Consider the initialization:

function initMyTinymce() {
    tinymce.init({
        selector: $(this).attr("id"),
        directionality: "ltr",
    });
}

Is it possible to add properties to tinyMCE after init()?

For example:

plugins: "link,code,textcolor",
relative_urls: false,
convert_urls: false,
remove_script_host: false

I'm using TinyMce 4.1.6 (2014-10-08).

2 Answers 2

9

Yes, this is possible, but parameters that get read on initialisation only won't have an impact if they get set later on. Example: To change the parameter plugins changes nothing because the tinymce UI has been rendered already.

To set a paramter after initialization use:

editor.settings.my_setting = 'abcd',
3
  • 1
    logical follow up: how does one re-render editor or destruct/re-initialize editor?
    – Brad Kent
    Commented Apr 13, 2017 at 19:37
  • take a look here: stackoverflow.com/questions/4651676/…
    – Thariama
    Commented Apr 15, 2017 at 13:19
  • This is valid for older versions too (3.01 in my case). Thx @Thariama Commented Nov 25, 2019 at 15:18
1
function Tiny_readonly(id, action) {
    tinymce.get(id).remove();
        if (action == 0) {
            tinymce.init({
                selector: 'textarea#' + id,
                skin: 'dark',
                height: 200,
                readonly: true,
                toolbar: false,
                menubar: false,
                statusbar: false,
                init_instance_callback: function(editor) {},
            });
        } else {
            tinymce.init({
                selector: 'textarea#' + id,
                height: 250,
                menubar: false,
                skin: 'default',
                plugins: [
                    'advlist autolink lists link  charmap print preview anchor',
                    'searchreplace visualblocks code fullscreen',
                    'insertdatetime media table paste code help wordcount'
                ],
                toolbar: 'undo redo | formatselect | ' +
                    'bold italic backcolor | alignleft aligncenter ' +
                    'alignright alignjustify | bullist numlist outdent indent | ' +
                    'removeformat | table',
                content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
            });
        }
}
1
  • 1
    While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
    – Suraj Rao
    Commented Nov 7, 2021 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.