javascript 初始化后设置 TinyMCE 编辑器参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8946391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:06:43  来源:igfitidea点击:

Set TinyMCE Editor Param after Initialized

javascriptwordpresstinymce

提问by Aramael Pena-Alcantara

I am trying to set the readonlyparameter in tinyMCE to trueafter tinyMCE has been initalized. I am trying to use this with wordpress to disable the postEditor if the post has already been published. I found some sources claiming that you can call:

我试图readonly在 tinyMCE 初始化true之后将 tinyMCE 中的参数设置为。如果帖子已经发布,我正在尝试将其与 wordpress 一起使用以禁用 postEditor。我发现一些消息来源声称您可以致电:

tinyMCE.activeEditor.execCommand(
    'mceSetAttribute',
    false,
    {name:'readonly',value:true}
);

but I have been having no luck with that and have not found a solution.

但我一直没有运气,也没有找到解决方案。

回答by Thariama

An easier way to set this is tinyMCE.activeEditor.settings.readonly = true;But the problem here is that the readonly setting affects the way tinymce gets initialized. So setting it after tinymce is initialized won't have a big impact.

一种更简单的设置方法是tinyMCE.activeEditor.settings.readonly = true;但这里的问题是只读设置会影响 tinymce 的初始化方式。所以在tinymce初始化后设置不会有太大影响。

What you can do to prevent users from editing content in your editor is to set the contenteditable attribute of the editors iframe body to false:

为了防止用户在您的编辑器中编辑内容,您可以做的是将编辑器 iframe 正文的 contenteditable 属性设置为 false:

tinymce.activeEditor.getBody().setAttribute('contenteditable', false);