1

Topic: Readonly mode on off without reload

I have a TinyMCE editor (3.4.5) that I want to switch between readonly and editable modes. The editor typically starts out in editable mode, and I seem able to switch it to readonly mode with the following command:

ed.execCommand("contentReadOnly", false, ed.getElement());

However, once I've done this, I want to then switch back into editable mode in the future. I tried running the following, but of course this does not work:

ed.execCommand("contentReadOnly", true, ed.getElement());

I'm wondering if someone could tell me what I can do to re-enable editable mode on TinyMCE?

I've seen some people suggest that I must destroy the editor and re-initialize it with readonly:false to accomplish this, but this destroy+re-initialize act has caused me a ton of problems elsewhere. Calling tinyMCE.init twice seems to throw security errors and often results in a dead or completely blank and unusable editor.

2

Re: Readonly mode on off without reload

contentReadOnly is not a TinyMCE command. I think it's a Firefox only command.

A better way to get what you want is probably use the nonEditable plugin.
http://www.tinymce.com/tryit/noneditable_content.php
You can wrap the entire content of the editor in a non-editable element, that effectively disable all the editing. And you can simply remove the non-editable element when you want to enable edit again.

3

Re: Readonly mode on off without reload

@jlo

Thanks so much for pointing out this noneditable plugin! I had not noticed it before, and its solved my problem.

Instead of wrapping all of the editor contents in a <div>, what I've actually done is toggled the noneditable CSS class directly on the <body> tag of the editor document. Its working like a charm!

Cheers!