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

发布于 2024-12-28 06:43:45 字数 290 浏览 4 评论 0原文

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

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

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

I am trying to set the readonly parameter in tinyMCE to true after 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:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏九 2025-01-04 06:43:45

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

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

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

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.

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:

tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文