Set TinyMCE Editor Param after Initialized

2019-02-16 14:31发布

问题:

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.

回答1:

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);