如何在tinymce完全初始化后禁用它

How to disable tinymce after it is fully initialized?

本文关键字:初始化 tinymce      更新时间:2023-09-26

现在,我正在使用这行代码禁用tinyMCE

tinyMCE.get('tinymce_id').getBody().setAttribute('contenteditable', false);

但是,它在初始化时似乎并没有被禁用。只有当我选择单选按钮时,它才会被禁用。

如何在初始化特定的tinyMCE编辑器后禁用它?如果可能的话,我想要一个同样适用于IE8的答案。提前感谢!


JQuery:

 require(['tinymce'],function(){
            var disableInputs = function(){
                if($('input[name=type]:checked').val()==1){
                    tinyMCE.get('newsletter_message').getBody().setAttribute('contenteditable', false);
                    tinyMCE.get('category_message').getBody().setAttribute('contenteditable', true);
                }else{
                    tinyMCE.get('newsletter_message').getBody().setAttribute('contenteditable', true);
                    tinyMCE.get('category_message').getBody().setAttribute('contenteditable', false);
                }
            };
            $('input[name=type]').on('click',function(){
                disableInputs();
            });
            disableInputs();
        });

HTML:

<input type="radio" value=1 name=type/>
<div id="newsletter"> tinymce with id of newsletter_message initializes here... </div>
<input type="radio" value=0 name=type/>
<div id="category"> tinymce with id of category_message initializes here... </div>

您尝试过设置readonly配置参数吗?根据TinyMCE文件(http://www.tinymce.com/wiki.php/Configuration3x:readonly):

此选项使您能够在只读模式下指定make编辑器实例。当它们处于只读模式时,什么都不能改变,内容只呈现给用户。您可以将其与body_class结合使用,为只读模式呈现不同的视觉呈现。

因此,您可以添加类似(来自同一来源)的内容:

// Move focus to specific element
tinyMCE.init({
        ...
        theme : "advanced",
        readonly : 1
});